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-5
Creating a Connection
Create Connection Factories at Runtime
You can, optionally, create ConnectionFactory objects at runtime. However, this
requires references to NSJMS specific classes that will reduce the portability of the
JMS application.
This code fragment creates a QueueConnectionFactory with the default settings:
QueueConnectionFactory factory=
com.tandem.nsjms.client.JmsQueueConnectionFactory();
This code fragment creates a TopicConnectionFactory with the default settings:
TopicConnectionFactory factory=
com.tandem.nsjms.client.JmsTopicConnectionFactory();
Use the Factory Object to Create a Connection
You use a queue or topic connection method on the factory object to create a
connection.
Creating a queue connection is shown in this code fragment taken from the
SimpleSender.java sample program file:
QueueConnection connection = factory.createQueueConnection();
Creating a topic connection is shown in this code fragment taken from the
SimpleSender.java sample program file:
TopicConnection connection = factory.createTopicConnection();
Start the Connection
The JMS specification defines that connections should be created in a stopped state.
You must start the connection to enable MessageConsumers associated with the
connection to receive messages. To start the connection, run this command:
connection.start();
Create a Session
After you have started the connection, use a queue or topic session method to create a
session.
Creating a queue session is shown in this code fragment taken from the
SimpleSender.java sample program file:
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Creating a topic session is shown in this code fragment taken from the
SimpleSender.java sample program file:
TopicSession session = connection.createTopicSession(false,
Session.CLIENT_ACKNOWLEDGE);