The example program examples.jms.MQeJMSIVT_JNDI can be used to test your installation using JNDI. This is very similar to the examples.jms.MQeJMSIVT program, except that it uses JNDI to retrieve the connection factory and the queue that it uses. Before you can run this program you must store these two administered objects in a JNDI namespace:
Entry name | Java™ class | Description |
ivtQCF | MQeJNDIQueueConnectionFactory | A QueueConnectionFactory configured to use an MQe queue manager |
ivtQ | MQeJMSJNDIQueue | A Queue configured to represent an MQe queue which is local to the queue manager used by the ivtQCF entry |
The program examples.jms.CreateJNDIEntry or the MQeJMSAdmin tool , explained in the following section, can be used to create these entries. Larger installations may have a Lightweight Directory Access Protocol (LDAP) directory available, but for smaller installations a file system namespace may be more appropriate. When you have decided on a namespace you must obtain the corresponding JNDI class files to support the namespace and add these to your classpath. These will vary depending on your choice of namespace and the version of Java you are using.
You must always have the javax.naming.* classes on your classpath. If you are using Java 1 (for example a 1.1.8 JRE) you must obtain a copy of the jndi.jar file and add it to your classpath. If you are using Java 2 (a 1.2 or later JRE) the JRE may contain these classes itself.
If you want to use an LDAP directory, you must obtain JNDI classes that support LDAP, for example Sun's ldap.jar or IBM's ibmjndi.jar, and add these to your classpath. Some Java 2 JREs may already contain Sun's classes for LDAP. See also the section below about LDAP support for Java classes.
java examples.jms.CreateJNDIEntry -url<providerURL> [-icf<initialContextFactory>][-ldap] [-qcf<entry name><MQe queue manager ini file>] [-q<entry name><MQe queue name>]An alternative argument to use is:
java examples.jms.CreateJNDIEntry -hIn the previous two examples:
com.sun.jndi.fscontext.RefFSContextFactory
The url, -url, must be specified and either a QueueConnectionFactory (-qcf) or a Queue (-q), or both, must be specified. The context factory, -icf, is optional and defaults to a file system directory. The LDAP flag, -ldap, should be specified if an LDAP directory is being used, this prefixes the entry name with "cn=", which is required by LDAP.
java examples.jms.CreateJNDIEntry -url file://d:/MQe/data/jndi -qcf ivtQCF d:\MQe\exampleQM\exampleQM.iniNote that forward slashes are used in the url, even if the file system itself uses back slashes. The url directory must already exist. To add an entry for the queue you would type (all on one line):
java examples.jms.CreateJNDIEntry -url file:// d:/MQe/data/jndi -q ivtQ SYSTEM.DEFAULT.LOCAL.QUEUE
You could use another local queue instead of the SYSTEM.DEFAULT.LOCAL.QUEUE.
You could also specify the queue name as exampleQM+SYSTEM.DEFAULT.LOCAL.QUEUE, where exampleQM is the name of the queue manager. If the name of the queue manager is not specified, the local queue manager is used.
java examples.jms.CreateJNDIEntry -url file://d:/MQe/data/jndi -qcf ivtQCF d:\MQe\exampleQM\exampleQM.ini -q ivtQ SYSTEM.DEFAULT.LOCAL.QUEUEAgain, you should type all of this command on one line. A maximum of one connection factory and one queue can be added at a time.
java examples.jms.MQeJMSIVT_JNDI -url<providerURL>where <providerURL> is the specified URL of the JNDI initial context. By default the program uses the file system context for JNDI:
com.sun.jndi.fscontext.RefFSContextFactoryIf necessary you can specify an alternative context:
java examples.jms.MQeJMSIVT_JNDI -url<providerURL> -icf<initialContextFactory>You can optionally add a -t flag to turn tracing on:
java examples.jms.MQeJMSIVT_JNDI -url<providerURL> -icf<initialContextFactory> -tTo use the entries in the file system directory created in the CreateJNDIEntry example above, type:
java examples.jms.MQeJMSIVT_JNDI -url file://d:/MQe/data/jndi
using context factory 'com.sun.jndi.fscontext.RefFSContextFactory' for the directory using directory url 'file://d:/MQe/data/jndi' checking classpath found JMS interface classes found MQe JMS classes found MQe base classes found jndi.jar classes found com.sun.jndi.fscontext.RefFSContextFactory classes Looking up connection factory in jndi Looking up queue in jndi Creating connectionThe rest of the output should be similar to that from the example without JNDI. You can also run the two other example programs, examples.jms.PTPSample01 and example .jms.PTPSample02, using JNDI. These programs requires the same JMS and MQe jar files on the classpath as the MQeJMSIVT_JNDI program, that is:
java examples.jms.PTPSsample01 -url<providerURL>As in the previous example, providerURL is the URL of the JNDI initial context. By default, the program uses the file system context for JNDI, that is com.sun.jndi.fscontext.RefFSContextFactory. If necessary you can specify an alternative context:
java examples.jms.PTPSsample01 -url<providerURL> -icf<initialContextFactory>You can optionally add a "-t" flag to turn tracing on: java examples.jms. PTPSsample01 -url <providerURL><-icf initialContextFactory> -t . To use the entries in the file system directory created in the CreateJNDIEntry example above, you would type:
java examples.jms.PTPSample01 -url file://d:/MQe/data/jndi
The program examples.jms.PTPSample02 uses message listeners and filters. It creates a QueueReceiver with a filter "colour='blue'" and creates a message listener for it. It creates a second QueueReceiver with a filter "colour='red'" and also creates a message listener. It sends four messages to a queue, two with the property "colour" set to "red" and two with the property "colour" set to "blue", and checks that the message listeners receive the correct messages. The program has the same command line parameters as the PTPSample01 program and can be run in the same way. Simply substitute PTPSample02 for PTPSample01.