Provider for JMS
Using the JMS Sample Applications with AMQP
You can use the JMS sample applications in the Software AG_directory \UniversalMessaging\java\instance_name\bin directory, except the JMS queue browser, over the Advanced Message Queuing Protocol (AMQP).
The JMS sample applications have been tested against the Qpid JMS client 0.52.0 library, which is not part of the Universal Messaging installation.
Before running a JMS sample application, you must perform the following actions:
Download the Qpid JMS client 0.52.0 binaries from the Apache Qpid website and add all necessary jar files to the classpath of the application.
Modify the CONTEXT_FACTORY and PROVIDER_URL environment variables.
Keep in mind that AMQP connections require the AMQP plugin to be enabled on the realm and work only over nsp and nsps interfaces.
Installing the Qpid JMS Client Library
The Qpid JMS client 0.52.0 library requires JMS 2.0, which is included in the apache-qpid-jms-0.52.0-bin.tar.gz binaries package. To use the Qpid JMS client 0.52.0 library with a JMS application, perform the following steps:
1. Download the apache-qpid-jms-0.52.0-bin.tar.gz binaries package from the
Apache Qpid website.
2. Add the jar files from the package to the classpath of the JMS application that you want to use:
a. Open the .conf file of the application in a text editor.
b. Type the following line to add all necessary jar files:
wrapper.java.classpath.n=<relative_path_to_package>*.jar
where n is a unique positive integer.
Modifying the Environment Variables
To switch to AMQP, you must change the following environment variables before running the JMS sample applications:
Environment Variable | Description |
CONTEXT_FACTORY | The name of the ContextFactory class used by the sample application (default: com.pcbsys.nirvana.nSpace.NirvanaContextFactory). When you use an AMQP connection, change this to: org.apache.qpid.jms.jndi.JmsInitialContextFactory to use the Qpid JMS client libraries. |
PROVIDER_URL | The URL of your local realm from which JNDI entries will be looked up (default: nsp://localhost:9000). When you use an AMQP connection, change this to: amqp://localhost:9000 - when using a plain AMQP connection, connecting to a standard nsp interface. amqps://localhost:9000 - when using a plain AMQP connection over a secure socket connection, connecting to an nsps interface. |
Note:
When you use AMQP with the JMS sample applications, the <factoryname> parameter is ignored, but it is still required. This is due to the internal implementation of the client libraries.
Plain AMQP Pub/Sub Example
The following example assumes that you have an existing topic MyTopic configured on the realm server and bound in the JNDI context, and that the client tries to connect to an nsp interface.
To start a subscriber:
1. Start a "Java examples" command prompt.
2. Set the following environment variables:
set CONTEXT_FACTORY=org.apache.qpid.jms.jndi.JmsInitialContextFactory
set PROVIDER_URL=amqp://<hostname>:<port>
3. Start the jmssub application by running the following command:
jmssub ignored topic.MyTopic
At this point the jmssub application will be running over AMQP and will receive any messages published on the MyTopic topic.
To start a publisher:
1. Start a "Java examples" command prompt.
2. Set the following environment variables:
set CONTEXT_FACTORY=org.apache.qpid.jms.jndi.JmsInitialContextFactory
set PROVIDER_URL=amqp://<hostname>:<port>
3. Start the jmssub application by running the following command:
jmspub ignored topic.MyTopic 10
At this point the jmspub application will be running over AMQP and will send 10 messages to the MyTopic topic.
AMQP over alternative TLS example
The following example assumes that you have an existing topic MyTopic configured on the realm server and bound in the JNDI context and that the client tries to connect to a NSPS interface.
To start a subscriber:
1. Start a "Java examples" command prompt
2. Set the following environment variables:
set CONTEXT_FACTORY=org.apache.qpid.jms.jndi.JmsInitialContextFactory
set PROVIDER_URL=amqps://<hostname>:<port>
3. Start the jmssub application by running the following command:
jmssub ignored topic.MyTopic
At this point the jmssub application will be running over AMQP and will receive any messages published on the MyTopic topic
To start a publisher:
1. Start a "Java examples" command prompt
2. Set the following environment variables:
set CONTEXT_FACTORY=org.apache.qpid.jms.jndi.JmsInitialContextFactory
set PROVIDER_URL=amqps://<hostname>:<port>
3. Start the jmssub application by running the following command:
jmspub ignored topic.MyTopic 10
At this point the jmspub application will be running over AMQP and will send 10 messages to the MyTopic topic.
Note:
If the NSPS interface on the realm has been configured to use the certificates generated by the "CertificateGenerator" then you don't need to make any changes to the client applications. However if you are using different certificates, then in each command prompt, you need to additionally set the certificate locations by executing the following set commands:
set CAKEYSTORE=<TRUST KEYSTORE PATH>
set CAKEYSTOREPASSWD=<TRUST KEYSTORE PASSWORD>
set CKEYSTORE=<CLIENT KEYSTORE PATH>
set CKEYSTOREPASSWD=<CLIENT KEYSTORE PASSWORD>