To use SwiftMQ's file system JNDI provider instead of SwiftMQ's built-in federated JNDI has some advantages. First, one can avoid to create an additional JMS connection, because SwiftMQ's federated JNDI uses a JMS connection to perform a JNDI lookup. Next, SwiftMQ's file system provider uses a simple filesystem directory to store JNDI objects which can be easily transfered to clients, can be checked into version control systems and so on.
SwiftMQ's JNDI file system provider is part of the swiftmq.jar from releases 9.3.0 and up.
Create a new JNDI replication either with SwiftMQ Explorer/CLI or directly in the routerconfig.xml.
<swiftlet name="sys$jndi"> <aliases> <alias name="testqueue" map-to="testqueue@router1"/> </aliases> <jndi-replications> <jndi-replication name="fscontext" destination-context="/" enabled="true"> <environment-properties> <environment-property name="java.naming.factory.initial" value="com.swiftmq.jndi.fs.InitialContextFactoryImpl"/> <environment-property name="java.naming.provider.url" value="file:///home/swiftmq/jndi"/> </environment-properties> </jndi-replication> <remote-queues> <remote-queue name="testqueue@router2"/> </remote-queues> </swiftlet>
Then start the router. After startup, you'll have all JNDI objects under "/home/swiftmq/jndi" (or another directory you've specified for "java.naming.provider.url"). Copy this directory to a save location, because the router removes all bindings during stop. Because the whole JNDI content of the router is now stored in that directory, you can remove (or disable) the JNDI replication configuration. You can activate it again if the content changes, e.g. you create a new connection factory.
To lookup JNDI objects from a JMS client, you need to change the client's JNDI properties.
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.swiftmq.jndi.fs.InitialContextFactoryImpl"); env.put(Context.PROVIDER_URL, "file:///home/swiftmq/jndi"); InitialContext ctx = new InitialContext(env); QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("plainsocket@router1");