Search in sources :

Example 26 with JMSContext

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

the class ExportImportJournalTestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, 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, TimeoutUtil.adjust(5000));
        if (expectReceivedMessage) {
            assertNotNull(text);
            assertEquals(expectedText, text);
        } else {
            assertNull("should not have received any message", text);
        }
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 27 with JMSContext

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

the class PrintDataTestCase method sendMessage.

protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
    ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
    assertNotNull(cf);
    Destination destination = (Destination) ctx.lookup(destinationLookup);
    assertNotNull(destination);
    try (JMSContext context = cf.createContext("guest", "guest", JMSContext.AUTO_ACKNOWLEDGE)) {
        TextMessage message = context.createTextMessage(text);
        message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        context.createProducer().send(destination, message);
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage)

Example 28 with JMSContext

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

the class PrintDataTestCase method receiveMessage.

protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, 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, TimeoutUtil.adjust(5000));
        if (expectReceivedMessage) {
            assertNotNull(text);
            assertEquals(expectedText, text);
        } else {
            assertNull("should not have received any message", text);
        }
    }
}
Also used : Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext)

Example 29 with JMSContext

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

the class LifecycleCounterMDB method onMessage.

@Override
public void onMessage(Message message) {
    try {
        log.trace(this + " received message " + message);
        final Destination replyTo = message.getJMSReplyTo();
        // ignore messages that need no reply
        if (replyTo == null) {
            log.trace(this + " noticed that no reply-to replyTo has been set. Just returning");
            return;
        }
        try (JMSContext context = factory.createContext()) {
            String reply = Constants.REPLY_MESSAGE_PREFIX + ((TextMessage) message).getText();
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
        }
    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
}
Also used : Destination(javax.jms.Destination) JMSException(javax.jms.JMSException) JMSContext(javax.jms.JMSContext)

Example 30 with JMSContext

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

the class ClusteredMessagingTestCase method receiveMessage.

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

Aggregations

JMSContext (javax.jms.JMSContext)120 Test (org.junit.Test)57 JMSConsumer (javax.jms.JMSConsumer)44 ConnectionFactory (javax.jms.ConnectionFactory)35 Destination (javax.jms.Destination)30 TextMessage (javax.jms.TextMessage)28 JMSProducer (javax.jms.JMSProducer)27 Message (javax.jms.Message)18 JMSRuntimeException (javax.jms.JMSRuntimeException)13 TemporaryQueue (javax.jms.TemporaryQueue)13 InitialContext (javax.naming.InitialContext)12 JMSException (javax.jms.JMSException)10 Queue (javax.jms.Queue)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)7 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 QueueConnectionFactory (javax.jms.QueueConnectionFactory)4 Context (javax.naming.Context)4 NamingException (javax.naming.NamingException)4