Chapter 21. Using the qpid-jms AMQP 1.0 client
21.1. QPID AMQP 1.0 JMS Client Configuration
This chapter details various configuration options for the qpid-jms client, such as how to configure and create a JNDI
InitialContext
, the syntax for its related configuration, and various URI options that can be set when defining a ConnectionFactory
.
Applications use a JNDI
InitialContext
, itself obtained from an InitialContextFactory
, to look up JMS objects such as ConnectionFactory
. The Qpid JMS client provides an implementation of the InitialContextFactory
in class org.apache.qpid.jms.jndi.JmsInitialContextFactory. This may be configured and used in three main ways:
- Via
jndi.properties
file on the Java Classpath. - By including a file named
jndi.properties
on the Classpath and setting thejava.naming.factory.initial
property to valueorg.apache.qpid.jms.jndi.JmsInitialContextFactory
, the QpidInitialContextFactory
implementation will be discovered when instantiating InitialContext object.javax.naming.Context ctx = new javax.naming.InitialContext();
The particularConnectionFactory
, Queue and Topic objects you wish the context to contain are configured using properties (the syntax for which is detailed below) either directly within thejndi.properties
file, or in a separate file which is referenced injndi.properties
using thejava.naming.provider.url
property. - Via system properties.
- By setting the
java.naming.factory.initial
system property to valueorg.apache.qpid.jms.jndi.JmsInitialContextFactory
, the QpidInitialContextFactory
implementation will be discovered when instantiating InitialContext object.javax.naming.Context ctx = new javax.naming.InitialContext();
The particularConnectionFactory
, Queue and Topic objects you wish the context to contain are configured as properties in a file, which is passed using thejava.naming.provider.url
system property. The syntax for these properties is detailed below. - Programmatically using an environment Hashtable.
- The InitialContext may also be configured directly by passing an environment during creation:
Hashtable<Object, Object> env = new Hashtable<Object, Object>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); javax.naming.Context context = new javax.naming.InitialContext(env);
The particularConnectionFactory
, Queue and Topic objects you wish the context to contain are configured as properties (the syntax for which is detailed below), either directly within the environment Hashtable, or in a separate file which is referenced using thejava.naming.provider.url
property within the environment Hashtable.
The property syntax used in the properties file or environment Hashtable is as follows:
Property | Syntax |
---|---|
ConnectionFactory | connectionfactory.lookupName = URI |
Queue | queue.lookupName = queueName |
Topic | topic.lookupName = topicName |
As an example, consider the following properties used to define a
ConnectionFactory
, Queue, and Topic:
connectionfactory.myFactoryLookup = amqp://localhost:5672 queue.myQueueLookup = queueA topic.myTopicLookup = topicA
These objects could then be looked up from a Context as follows:
ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup"); Queue queue = (Queue) context.lookup("myQueueLookup"); Topic topic = (Topic) context.lookup("myTopicLookup");