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 JMS resources, such as connections, sessions and consumers, in JMS 2 can be automatically closed on error.
In this instance we auto close a connection after a subsequent call to a JMS producer send fails
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");
try
(
JMSContext jmsContext = cf.createContext()
)
JMSProducer jmsProducer = jmsContext.createProducer();
jmsProducer.send(queue, "this message will fail security!");
System.out.println("expected exception from jmsProducer.send: " + e.getMessage());
finally
{
if (initialContext != null)
{
initialContext.close();
}
}