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 Manual—522356-006
4-4
Creating a Connection
Creating a Connection
A JMS client uses a ConnectionFactory object to create a connection with NSJMS. To
create a connection between a JMS client and NSJMS:
Create an Initial Context on page 4-4
Retrieve the Connection Factory on page 4-4
Use the Factory Object to Create a Connection on page 4-5
Start the Connection on page 4-5
Create a Session on page 4-5.
Create an Initial Context
You must create an initial context to retrieve the ConnectionFactory object from a JNDI
namespace. This is shown in the code fragment taken from the SimpleSender.java
sample program file:
import javax.jms.*;
import javax.naming.*;
.
.
.
Context jndiContext = new InitialContext();
Retrieve the Connection Factory
After you have created an initial context, perform a JNDI lookup to retrieve the
ConnectionFactory object from a JNDI namespace.
Retrieving a QueueConnectionFactory is shown in this code fragment taken from the
SimpleSender.java sample program file:
QueueConnectionFactory factory = (QueueConnectionFactory)
jndiContext.lookup(“QueueConnectionFactory”);
Retrieving a TopicConnectionFactory is shown in this code fragment taken from the
SimpleSender.java sample program file:
TopicConnectionFactory factory = (TopicConnectionFactory)
jndiContext.lookup(“TopicConnectionFactory”);
Note. At this time, no interoperability exists among the JMS providers. A user achieves
platform interoperability by using a JMS provider that is present on all the required platforms.
Two or more JMS implementations can coexist. A user must establish JMS connections to
each provider from the same Java program. The user can then receive messages from one
provider and send the message using another provider. NSJMS includes code that transforms
foreign messages to native format when the messages are sent using a NSJMS session.
Note. To protect the JMS application from NSJMS-specific information, factory objects are
stored in a JNDI namespace.