Search in sources :

Example 1 with MessageHandler

use of org.apache.activemq.artemis.api.core.client.MessageHandler in project wildfly by wildfly.

the class ArtemisMessagingTestCase method testMessaging.

@Test
public void testMessaging() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<ClientMessage> message = new AtomicReference<ClientMessage>();
    ClientConsumer consumer = session.createConsumer(QUEUE_EXAMPLE_QUEUE);
    consumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(ClientMessage m) {
            try {
                m.acknowledge();
                message.set(m);
                latch.countDown();
            } catch (ActiveMQException e) {
                e.printStackTrace();
            }
        }
    });
    String text = UUID.randomUUID().toString();
    sendMessage(text);
    assertTrue(latch.await(1, SECONDS));
    assertEquals(text, message.get().getStringProperty(BODY));
}
Also used : MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 MessageHandler (org.apache.activemq.artemis.api.core.client.MessageHandler)1 Test (org.junit.Test)1