High Quality Enterprise Messaging.

Using Sun's File System Context Provider

To use Sun's file system JNDI provider instead of SwiftMQ's built-in JNDI has some advantages. First, one can avoid to create an additional JMS connection, because SwiftMQ's JNDI uses a JMS connection to perform a JNDI lookup. Next, Sun's file system provider uses a simple file called ".bindings" which can be easily transfered to clients, can be checked into version control systems and so on.

Configuration

First of all, download the JNDI file system provider from Sun's web site:

Click to Download

Unpack the distribution and put "fscontext.jar" and "providerutil.jar" into the router's class path.

Create a new JNDI replication either with SwiftMQ Explorer/CLI or directly in the routerconfig.xml.

Example:

    <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.sun.jndi.fscontext.RefFSContextFactory"/>
            <environment-property name="java.naming.provider.url"
                           value="file:///home/swiftmq"/>
          </environment-properties>
        </jndi-replication>
      <remote-queues>
        <remote-queue name="testqueue@router2"/>
      </remote-queues>
    </swiftlet>

Then start the router. After startup, you'll find a file ".bindings" under "/home/swiftmq" (or another directory you've specified for "java.naming.provider.url"). Copy this file to a save location, because the router removes all bindings during stop. Because the whole JNDI content of the router is now stored in the ".bindings" file, 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 have to put "fscontext.jar" and "providerutil.jar" into the client's class path. Further, you need to change the client's JNDI properties.

Example:

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:///home/swiftmq/save");
    InitialContext ctx = new InitialContext(env);
    QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("plainsocket@router1");