Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to use a the PropertiesFileInitialContextFactory

This ContextFactory uses a java properties file to setup initial values.

This is the example properties file.

No Format

java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialConextFactory

# use the following property to configure the default connector
#java.naming.provider.url - ignored.

# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.local = amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue

# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.ibmStocks = stocks.nyse.ibm

# Register an AMQP destination in JNDI
#   NOTE: Qpid currently only supports direct,topics and headers
# destination.[jniName] = [BindingURL]
destination.direct = direct://amq.direct//directQueue

The property file allows a number of queues to be defined that can then be discovered via JNDI. There are four properties used by the PFICFactory.
connectionfactory.<jndiname> this is the Connection URL that the connection factory will use to perform connections.
queue.<jndiname> this defines a jms queue or in amqp a amq.direct exchange
topic.<jndiname> this defines a jms topic or in amqp a amq.topic exchange
destination.<jndiname> this takes a Binding URL and so can be used for defining all amq destinations, queues, topics and header matching.

In all of these properties the <jndiname> is the string value that would be given when performing a lookup.

NOTE: This does not create the destination on the broker. In AMQP destinations only exist once a consumer has connected to that resource. You should ensure that you have created the destination before publishing to it.

Example lookup code

The bindingValue is the String that would be placed in <jndiname> above.

Code Block
titleSimple JNDI lookup
borderStylesolid

// Load the properties file ... 
Properties properties = new Properties();
properties.load(propertiesfile_inputStream);

// Create the initial context
Context ctx = new InitialContext(properties);

// Perform the binds
object = ctx.lookup(bindingValue);

// Close the context when we're done
ctx.close();

How to use a JNDI Provider

Qpid will work with any JNDI provider capable of storing Java objects. We have a task to add our own initial context factory, but until that's available ....

...

Note that you need not cast the bound object back to an AMQConnectionFactory so all your current JMS apps that use JNDI can start using Qpid straight away.

How to create a TopicConnectionFactory and QueueConnectionFactory

AMQConnectionFactory implements TopicConnectionFactory and QueueConnectionFactory as well as the ConnectionFactory.