Universal Messaging 10.7 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Java | Code Examples | Provider for JMS
 
Provider for JMS
 
Using the AMQP Protocol
Java Client: JMS BytesMessage Publisher
Java Client: JMS BytesMessage Subscriber
Java Client: JMS MapMessage Publisher
Java Client: JMS MapMessage Subscriber
Java Client: JMS ObjectMessage Publisher
Java Client: JMS ObjectMessage Subscriber
Java Client: JMS StreamMessage Publisher
Java Client: JMS StreamMessage Subscriber
Java Client: JMS BytesMessage Queue Publisher
Java Client: JMS BytesMessage Queue Subscriber
Java Client: JMS Queue Browser
Using the AMQP Protocol
You can use the JMS sample applications, except the JMS queue browser, over the Advanced Message Queuing Protocol (AMQP). AMQP is defined by the ISO/IEC 19464 standard.
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 Proton JMS Client libraries.
*org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory to use the QPID Legacy 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.
AMQP connections require the AMQP plugin to be enabled on the realm and work only over the nsp and nsps interfaces. The connections do not work over nhp or nhps
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 a 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>