To run the example, simply type mvn verify from this directory,
or mvn -PnoServer verify if you want to start and create the server manually.
This example shows you how to send a message asynchronously to ActiveMQ Artemis and use a CompletionListener to be notified of the Broker receiving it
client-jndi.properties
file in the directory ../common/config
InitialContext initialContext = getContext();
Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
jmsContext = cf.createContext();
JMSProducer producer = jmsContext.createProducer();
producer.setAsync(new CompletionListener()
{
@Override
public void onCompletion(Message message)
{
System.out.println("message acknowledged by ActiveMQ");
latch.countDown();
}
@Override
public void onException(Message message, Exception e)
{
e.printStackTrace();
}
});
producer.send(queue, "this is a string");
return latch.await(5, TimeUnit.SECONDS);
finally
block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (jmsContext != null)
{
jmsContext.close();
}
}