JMSAdmin: Sample application for creating realm resources
Universal Messaging's Enterprise Manager tool supports JNDI using the same Universal Messaging Channel based context used by the JMSAdmin example.
The example (jmsdmin.java) source code demonstrates how to store Universal Messaging Provider for JMS components into a JNDI service provider. The default service provider for the example uses Universal Messaging's own Universal Messaging Context to store JMS objects references, however any JNDI context provider can be used, from LDAP through to NIS. The Universal Messaging context is discussed in more detail here. The Universal Messaging Context stores references in a channel called /naming/defaultContext.
JMSAdmin creates all required resources on a Universal Messaging realm. The command syntax is as follows:
java com.pcbsys.nirvana.nSpace.JMSAdmin
-DRNAME [-DPRINCIPAL] [-DPASSWORD] -DCONTEXT_FACTORY
-DPROVIDER_URL JMSAdmin bind | unbind | list | queueFactory |
topicFactory |connectionFactory | queue | topic name / alias
where the -D parameters have the following meaning:
RNAME is the realm name of the Universal Messaging server you wish to connect to. If no RNAME is provided the default RNAME of nsp://localhost:9000 is used.
You can specify a cluster of realms by specifying a comma-separated list of connection URLs, for example "nsp://localhost:9000,nsp://localhost:9010".
If you want to use a horizontal scalability connection factory, you can specify several connection URLs, using the horizontal scalability URL syntax.
Example:
(UM1,UM2)(UM3,UM4) - Indicates 2 clusters, one consisting of UM1 and UM2 and the other consisting of UM3 and UM4, so only 2 connections will be constructed here.
PRINCIPAL is the subject (if any) that your JNDI service provider requires.
PASSWORD is the PRINCIPAL's password for the JNDI service provider used.
CONTEXT_FACTORY is the fully qualified class name of the provider's context factory implementation. The default CONTEXT FACTORY is com.pcbsys.nirvana.nSpace.NirvanaContextFactory and is set automatically if no CONTEXT_FACTORY parameter is provided.
PROVIDER_URL is the custom URL required by the context factory and provider implementation. If no PROVIDER_URL parameter is passed, the default used is nsp://localhost:9000/.
As an example, assume we want to create a TOPIC called rates on a Universal Messaging realm running on our local machine. Typing:
java com.pcbsys.nirvana.nSpace.JMSAdmin bind topic rates
Will create an event in the /naming/defaultContext channel with the following information in the event properties of the event:
rates/RefAddr/0/Content=rates
rates/RefAddr/0/Type=Topic
rates/ClassName=javax.JMS.Topic
rates/FactoryName=com.pcbsys.nirvana.nJMS.TopicFactory
rates/RefAddr/0/Encoding=String
The topic rates will automatically be created on the Universal Messaging realm running on the PROVIDER_URL value. Assuming you wish to reference your local realm as a TopicConnectionFactory named TopicConnectionFactory in JMS, use the following command:
java com.pcbsys.nirvana.nSpace.JMSAdmin bind topicFactory TopicConnectionFactory
This will publish an event to the /naming/defaultContext channel with the following information in the event dictionary:
TopicConnectionFactory/RefAddr/0/Type=TopicConnectionFactory
TopicConnectionFactory /FactoryName=com.pcbsys.nirvana.nJMS.TopicConnectionFactoryFactory
TopicConnectionFactory/RefAddr/0/Encoding=String
TopicConnectionFactory/ClassName=javax.JMS.TopicConnectionFactory
TopicConnectionFactory/RefAddr/0/Content=nsp\://127.0.0.1\:9000
TopicConnectionFactory/RefAddr/0/Encoding=String
Creating a queue can be achieved using the following command:
java com.pcbsys.nirvana.nSpace.JMSAdmin bind queue movie
Likewise, a JMS queue connection factory called QueueConnectionFactory can be bound into a name space using the following command
java com.pcbsys.nirvana.nSpace.JMSAdmin bind queueFactory QueueConnectionFactory
Having run both queue related commands, the /naming/defaultContext channel will contain 4 events, each one pertaining to the 4 objects that have been bound, namely TopicConnectionFactory, QueueConnectionFactory, rates and movie. The Universal Messaging Context used with your JMS application will now be able to look up these objects and use them within your application.