Search in sources :

Example 51 with Message

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

the class MDBTestCase method doDeliveryActive.

private void doDeliveryActive(Destination destination, String mdbName) throws Exception {
    // ReplyingMDB has been deployed with deliveryActive set to false
    assertMDBDeliveryIsActive(mdbName, false);
    Connection connection = null;
    try {
        connection = cf.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        // send a message to the MDB
        MessageProducer producer = session.createProducer(destination);
        Message message = session.createMessage();
        message.setJMSReplyTo(replyQueue);
        producer.send(message);
        // the MDB did not reply to the message because its delivery is not active
        MessageConsumer consumer = session.createConsumer(replyQueue);
        Message reply = consumer.receive(TIMEOUT);
        assertNull(reply);
        executeMDBOperation(mdbName, "start-delivery");
        assertMDBDeliveryIsActive(mdbName, true);
        // WFLY-4470 check duplicate message when start delivery twice. Last assertNull(reply) should still be valid
        executeMDBOperation(mdbName, "start-delivery");
        // the message was delivered to the MDB which replied
        reply = consumer.receive(TIMEOUT);
        assertNotNull(reply);
        assertEquals(message.getJMSMessageID(), reply.getJMSCorrelationID());
        executeMDBOperation(mdbName, "stop-delivery");
        assertMDBDeliveryIsActive(mdbName, false);
        // send again a message to the MDB
        message = session.createMessage();
        message.setJMSReplyTo(replyQueue);
        producer.send(message);
        // the MDB did not reply to the message because its delivery is not active
        reply = consumer.receive(TIMEOUT);
        assertNull(reply);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 52 with Message

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

the class ReplyUtil method reply.

public static void reply(ConnectionFactory factory, Message message) {
    Connection connection = null;
    try {
        connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Destination destination = message.getJMSReplyTo();
        // ignore messages that need no reply
        if (destination == null)
            return;
        final MessageProducer replyProducer = session.createProducer(destination);
        final Message replyMsg = session.createMessage();
        replyMsg.setJMSCorrelationID(message.getJMSMessageID());
        replyProducer.send(replyMsg);
        replyProducer.close();
    } catch (JMSException e) {
        throw new RuntimeException(e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
            }
        }
    }
}
Also used : Destination(javax.jms.Destination) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 53 with Message

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

the class MessageDestinationTestCase method testMEssageDestinationResolution.

/**
     * Test a deployment descriptor based MDB
     * @throws Exception
     */
@Test
public void testMEssageDestinationResolution() throws Exception {
    this.messagingMdb.sendTextMessage("Say hello to " + MessagingEjb.class.getName());
    final Message reply = this.messagingMdb.receiveMessage(5000);
    Assert.assertNotNull("Reply message was null on reply queue", reply);
}
Also used : Message(javax.jms.Message) Test(org.junit.Test)

Example 54 with Message

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

the class MessagingEjb method reply.

public void reply(final Message message) throws JMSException {
    final Destination destination = message.getJMSReplyTo();
    // ignore messages that need no reply
    if (destination == null) {
        return;
    }
    final Message replyMsg = session.createTextMessage("replying to message: " + message.toString());
    replyMsg.setJMSCorrelationID(message.getJMSMessageID());
    this.sendMessage(replyMsg, destination, null);
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message)

Example 55 with Message

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

the class SetMessageDrivenContextInvocationTestCase method testSetMessageDrivenContext.

/**
     * Test that the {@link javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext)}
     * was invoked
     *
     * @throws Exception
     */
@Test
public void testSetMessageDrivenContext() throws Exception {
    this.jmsUtil.sendTextMessage("hello world", this.queue, this.replyQueue);
    final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
    Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
    final TextMessage textMessage = (TextMessage) reply;
    Assert.assertEquals("setMessageDrivenContext method was *not* invoked on MDB", SimpleMDB.SUCCESS_REPLY, textMessage.getText());
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

Message (javax.jms.Message)230 TextMessage (javax.jms.TextMessage)103 Test (org.junit.Test)91 Session (javax.jms.Session)86 JMSException (javax.jms.JMSException)77 MessageProducer (javax.jms.MessageProducer)64 ObjectMessage (javax.jms.ObjectMessage)52 MessageConsumer (javax.jms.MessageConsumer)50 Connection (javax.jms.Connection)45 BytesMessage (javax.jms.BytesMessage)37 Destination (javax.jms.Destination)30 MapMessage (javax.jms.MapMessage)26 Queue (javax.jms.Queue)20 ConnectionFactory (javax.jms.ConnectionFactory)18 QueueSession (javax.jms.QueueSession)17 MessageCreator (org.springframework.jms.core.MessageCreator)15 MessageListener (javax.jms.MessageListener)12 Map (java.util.Map)10 StreamMessage (javax.jms.StreamMessage)10 TemporaryQueue (javax.jms.TemporaryQueue)9