Using SwiftMQ's File System Context Provider


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">
        <alias name="testqueue" map-to="testqueue@router1"/>
        <jndi-replication name="fscontext" destination-context="/" enabled="true">
            <environment-property name="java.naming.factory.initial"
            <environment-property name="java.naming.provider.url"
        <remote-queue name="testqueue@router2"/>

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");