Search in sources :

Example 96 with Destination

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

the class AbstractMessagingHATestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, String expectedText) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        JMSConsumer consumer = context.createConsumer(destination);
        String text = consumer.receiveBody(String.class, 5000);
        assertNotNull(text);
        assertEquals(expectedText, text);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 97 with Destination

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

the class ActivationPropertyTimeoutMDB method onMessage.

@Override
public void onMessage(Message message) {
    try {
        log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText());
        // this should mean that second attempt for calling onMessage comes to play
        if (checker.getRolledback() > 0) {
            log.tracef("Discarding message '%s' as onMessage called for second time", message);
            return;
        }
        final Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to");
        }
        TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker);
        try (JMSContext context = factory.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText());
        }
        // would timeout txn - this timeout waiting has to be greater than 1 s
        // (see transactionTimeout activation config property)
        TxTestUtil.waitForTimeout(tm);
    } catch (Exception e) {
        throw new RuntimeException("onMessage method execution failed", e);
    }
}
Also used : Destination(javax.jms.Destination) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 98 with Destination

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

the class AnnotationTimeoutMDB method onMessage.

@Override
public void onMessage(Message message) {
    try {
        log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText());
        final Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to");
        }
        TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker);
        try (JMSContext context = factory.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText());
        }
        // would timeout txn when TransactionTimeout be cared
        TxTestUtil.waitForTimeout(tm);
    } catch (Exception e) {
        throw new RuntimeException("onMessage method execution failed", e);
    }
}
Also used : Destination(javax.jms.Destination) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 99 with Destination

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

the class NoTimeoutMDB method onMessage.

@Override
public void onMessage(Message message) {
    try {
        log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText());
        final Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to");
        }
        TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker);
        TxTestUtil.addSynchronization(tm.getTransaction(), checker);
        try (JMSContext context = factory.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText());
        }
    } catch (Exception e) {
        throw new RuntimeException("onMessage method execution failed", e);
    }
}
Also used : Destination(javax.jms.Destination) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 100 with Destination

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

the class ClusteredMessagingTestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, String expectedText) throws NamingException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest")) {
        JMSConsumer consumer = context.createConsumer(destination);
        receiveMessage(consumer, expectedText);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Aggregations

Destination (javax.jms.Destination)137 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)38 JMSException (javax.jms.JMSException)33 Message (javax.jms.Message)27 Session (javax.jms.Session)27 MessageProducer (javax.jms.MessageProducer)22 Connection (javax.jms.Connection)15 ConnectionFactory (javax.jms.ConnectionFactory)15 JMSContext (javax.jms.JMSContext)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 MessageConsumer (javax.jms.MessageConsumer)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 ObjectMessage (javax.jms.ObjectMessage)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 MapMessage (javax.jms.MapMessage)7 Queue (javax.jms.Queue)7 Map (java.util.Map)6 HashMap (java.util.HashMap)5 JMSConsumer (javax.jms.JMSConsumer)5