I'm working with an existing web application (running in Tomcat 7.0.26) that normally communicates with external systems over IBM WebsphereMQ, via the JMS API. The code looks similar to:
Hashtable<String, String> env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
env.put(Context.PROVIDER_URL, providerURL);
// Note that this is instantiating an InitialDirContext,
// NOT an InitialContext!!!
Context context = new InitialDirContext(environment);
qcf = (QueueConnectionFactory)context.lookup(qcfName);
requestQueue = (Queue)context.lookup(requestQueueName);
responseQueue = (Queue)context.lookup(responseQueueName);
//... etc, usual type of JMS code
I'm now trying to make this work with ActiveMQ 5.10 client libraries. A restriction on my end is that I cannot modify the source code. The only thing I have to play with are the variables as shown in the above code:
initialContextFactory
is in the current case always set tocom.sun.jndi.fscontext.RefFSContextFactory
providerURL
is currently set to afile://C:/directory
URL, pointing to a.bindings
file as generated by "Managed JMS Objects" from WebsphereMQ ExplorerrequestQueueName
&responseQueueName
I'm now changing initialContextFactory
to org.apache.activemq.jndi.ActiveMQInitialContextFactory
, and providerURL
to tcp://localhost:61616
. Although I'm not getting any errors from the code, it doesn't work. I cannot see any connection in the ActiveMQ Web Admin console.
Researching on the web, I see that normally ActiveMQ JNDI with Tomcat is set up differently:
Resource
entries in context.xml- Create the InitialContext as
new InitialContext();
- get a 'sub context' as
envContext = (Context) initCtx.lookup("java:comp/env");
- Get the JMS objects from this sub context (using a "jms/" prefix)
But as I wrote before, this is not an option for me: although I have access to the code, I cannot modify it.
Does anybody know a way around this? How can I get ActiveMQ QueueConnectionFactory/Queue objects from an instance of InitialDirContext
, initialized only with INITIAL_CONTEXT_FACTORY and PROVIDER_URL, and presumably without any additional configuration on the Tomcat side (although if necessary I do have the option of changing the tomcat config as well).
Maarten