Show Table of Contents
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.propertiesfile on the Java Classpath. - By including a file named
jndi.propertieson the Classpath and setting thejava.naming.factory.initialproperty to valueorg.apache.qpid.jms.jndi.JmsInitialContextFactory, the QpidInitialContextFactoryimplementation 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.propertiesfile, or in a separate file which is referenced injndi.propertiesusing thejava.naming.provider.urlproperty. - Via system properties.
- By setting the
java.naming.factory.initialsystem property to valueorg.apache.qpid.jms.jndi.JmsInitialContextFactory, the QpidInitialContextFactoryimplementation 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.urlsystem 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.urlproperty within the environment Hashtable.
The property syntax used in the properties file or environment Hashtable is as follows:
Table 21.1. Property syntax
| 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");

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.