NonStop JMS User's Manual (H06.03+, J06.03+, NonStop JMS 3.0+)

NSJMS and JMS Client Applications
NonStop Server for Java Message Service User’s Manual522356-006
4-13
Best Practices for Developing a JMS Client
This code fragment creates a message listener for a topic:
import javax.jms.*;
public class MyClass implements MessageListener
{
public void onMessage(Message message)
{
System.out.println("The message is "+message);
.
.
.
}
}
.
.
.
MyClass listener =new MyClass();
topicSubscriber.setMessageListener(listener);
Best Practices for Developing a JMS Client
You should use caution when creating active connections to NSJMS. Multiple
connections are not recommended. Creating multiple Session objects from the same
connection is more efficient because sessions share access to the same connection.
A typical JMS client performs these JMS setup process tasks:
Uses JNDI to find a ConnectionFactory object.
Uses JNDI to find one or more Destination objects.
Uses the ConnectionFactory to create a JMS Connection with message delivery
inhibited.
Uses the Connection to create one or more JMS Sessions.
Uses a Session along with the Destinations to create MessageProducers and
MessageConsumers.
Instructs the Connection to start delivery of messages.
At this point a client has the basic JMS setup needed to produce messages and
consume messages using a MessageListener or a receive() loop. An example of
the recommended setup process is shown in Topic Publisher/Subscriber Sample Setup
(Recommended) on page 4-13. An example of a setup process that is not
recommended for use is shown in Topic Publisher/Subscriber Sample Setup (Not
Recommended) on page 4-14.
Note. Although multiple sessions are allowed, they should not be repetitively created for
Consumers or Producers.