Search in sources :

Example 11 with ObjectMessage

use of javax.jms.ObjectMessage in project wildfly by wildfly.

the class ObjectMessageTestCase method testObjectMessage.

/**
     * Test that the MDB can process a {@link ObjectMessage} without any classloading issues
     *
     * @throws Exception
     */
@Test
public void testObjectMessage() throws Exception {
    final String goodAfternoon = "Good afternoon!";
    // create the message
    final SimpleMessageInEarLibJar message = new SimpleMessageInEarLibJar(goodAfternoon);
    // send as ObjectMessage
    this.jmsUtil.sendObjectMessage(message, this.objectMessageQueue, this.objectMessageReplyQueue);
    // wait for an reply
    final Message reply = this.jmsUtil.receiveMessage(objectMessageReplyQueue, 5000);
    // test the reply
    Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageReplyQueue, reply);
    final SimpleMessageInEarLibJar replyMessage = (SimpleMessageInEarLibJar) ((ObjectMessage) reply).getObject();
    Assert.assertEquals("Unexpected reply message on reply queue: " + this.objectMessageReplyQueue, message, replyMessage);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) MDBAcceptingObjectMessage(org.jboss.as.test.integration.ejb.mdb.objectmessage.MDBAcceptingObjectMessage) SimpleMessageInEarLibJar(org.jboss.as.test.integration.ejb.mdb.objectmessage.SimpleMessageInEarLibJar) Test(org.junit.Test)

Example 12 with ObjectMessage

use of javax.jms.ObjectMessage in project wildfly by wildfly.

the class ObjectMessageTestCase method testObjectMessageWithObjectArray.

/**
     * Test that the MDB can process a {@link ObjectMessage} which consists of an array of objects,
     * without any classloading issues
     *
     * @throws Exception
     */
@Test
public void testObjectMessageWithObjectArray() throws Exception {
    final String goodMorning = "Good morning";
    final String goodEvening = "Good evening";
    // create the message
    final SimpleMessageInEarLibJar[] multipleGreetings = new SimpleMessageInEarLibJar[2];
    final SimpleMessageInEarLibJar messageOne = new SimpleMessageInEarLibJar(goodMorning);
    final SimpleMessageInEarLibJar messageTwo = new SimpleMessageInEarLibJar(goodEvening);
    multipleGreetings[0] = messageOne;
    multipleGreetings[1] = messageTwo;
    // send as ObjectMessage
    this.jmsUtil.sendObjectMessage(multipleGreetings, this.objectMessageOfArrayTypeQueue, this.objectMessageOfArrayTypeReplyQueue);
    // wait for an reply
    final Message reply = this.jmsUtil.receiveMessage(objectMessageOfArrayTypeReplyQueue, 5000);
    // test the reply
    Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, reply);
    final SimpleMessageInEarLibJar[] replyMessage = (SimpleMessageInEarLibJar[]) ((ObjectMessage) reply).getObject();
    Assert.assertTrue("Unexpected reply message on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, Arrays.equals(replyMessage, multipleGreetings));
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) MDBAcceptingObjectMessage(org.jboss.as.test.integration.ejb.mdb.objectmessage.MDBAcceptingObjectMessage) SimpleMessageInEarLibJar(org.jboss.as.test.integration.ejb.mdb.objectmessage.SimpleMessageInEarLibJar) Test(org.junit.Test)

Example 13 with ObjectMessage

use of javax.jms.ObjectMessage in project wildfly by wildfly.

the class JMSMessagingUtil method sendObjectMessage.

public void sendObjectMessage(final Serializable msg, final Destination destination, final Destination replyDestination) throws JMSException {
    final ObjectMessage message = session.createObjectMessage();
    message.setObject(msg);
    this.sendMessage(message, destination, replyDestination);
}
Also used : ObjectMessage(javax.jms.ObjectMessage)

Example 14 with ObjectMessage

use of javax.jms.ObjectMessage in project wildfly by wildfly.

the class QueueTestMDB method sendReply.

private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection();
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(destination);
        ObjectMessage message = session.createObjectMessage(e);
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) QueueSession(javax.jms.QueueSession)

Example 15 with ObjectMessage

use of javax.jms.ObjectMessage in project wildfly by wildfly.

the class RunAsMDBUnitTestCase method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
    Connection conn = connFactory.createConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue replyQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Hello world");
    msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    msg.setJMSReplyTo(replyQueue);
    Queue queue = lookup("java:jboss/" + queueName, Queue.class);
    MessageProducer producer = session.createProducer(queue);
    producer.send(msg);
    MessageConsumer consumer = session.createConsumer(replyQueue);
    Message replyMsg = consumer.receive(5000);
    Assert.assertNotNull(replyMsg);
    if (replyMsg instanceof ObjectMessage) {
        Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
        throw e;
    }
    Assert.assertTrue(replyMsg instanceof TextMessage);
    String actual = ((TextMessage) replyMsg).getText();
    Assert.assertEquals("SUCCESS", actual);
    consumer.close();
    producer.close();
    session.close();
    conn.close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)47 Message (javax.jms.Message)20 Test (org.junit.Test)18 JMSException (javax.jms.JMSException)16 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)11 Serializable (java.io.Serializable)10 Destination (javax.jms.Destination)9 Map (java.util.Map)8 BytesMessage (javax.jms.BytesMessage)8 MapMessage (javax.jms.MapMessage)8 MessageProducer (javax.jms.MessageProducer)7 TreeMap (java.util.TreeMap)6 MessageConsumer (javax.jms.MessageConsumer)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (models.ChatRoom.Event)4 Connection (javax.jms.Connection)3 QueueConnection (javax.jms.QueueConnection)3 QueueSession (javax.jms.QueueSession)3 StreamMessage (javax.jms.StreamMessage)3