I installed openMQ locally and it works fine. I used the following code to get the QueueConnectionFactory
using a JNDI lookup.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:///C:/objectstore");
Context ctx = new InitialContext(env);
QueueConnectionFactory myFactory = (QueueConnectionFactory) ctx.lookup("MyQueueConnection");
The above returns me the connection factory from where I also access the replyQueue
and requestQueue
.
This is how I setup the queues
imqobjmgr add -l "MyQueueConnection"" -j "java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContext
Factory" -j "java.naming.provider.url=file:///C://objectstore" -t qf -o "imqAddressList=mq://localhost:7676/jms"
imqobjmgr add -l "cn=DEVL.REQUEST" -j "java.naming.factory.initial=com.sun.jndi.fscontext.RefFSCon
textFactory" -j "java.naming.provider.url=file:///C://objectstore" -t q -o "imqDestinationName=requestQueue"
imqobjmgr add -l "cn=DEVL.REPLY" -j "java.naming.factory.initial=com.sun.jndi.fscontext.RefFSConte
xtFactory" -j "java.naming.provider.url=file:///C://objectstore" -t q -o "imqDestinationName=replyQueue"
My questions are:
How do I setup openMQ on a linux server so that I can access openMQ from a different server where the code will be running in a tomcat apache server (also a linux box).
What changes will I have to make to the code to get the
QueueConnectionFactory
from openMQ
sitting on a different server ?
I'm not running openMQ in GlassFish, I'm running openMQ on it's own (imqbrokerd.exe).
In all of my digging I haven't found anything to indicate that OpenMQ supplies a JNDI provider when it's used stand alone. It looks like that's provided by GlassFish. This means you'll need to use something like LDAP as an object store, which I haven't done yet.
Currently I've "cheated" by copying the .binding file (the one that's in c:\objectstore in your case) over to a filesystem that JMeter can see so I could reference it. As long as you use actual machine names, or IPs, instead of localhost that'll work but it's obviously not going to cut it for production.
On the Java side you could just drop JNDI completely and just instantiate com.sun.messaging.ConnectionFactory
directly. I used Spring to inject the connection factory. Note that I had to include my own a very simple OpenMQConnectionFactoryFactory (stolen from https://wikis.oracle.com/display/GlassFish/OpenMQSpringConnectionConsumer) because com.sun.messaging.ConnectionFactory isn't a bean.
<bean id="connectionfactoryfactory"
class="myownlibrary.messaging.factory.OpenMQConnectionFactoryFactory">
<property name="properties">
<props>
<prop key="imqAddressList">qa29-vm:7676</prop>
<prop key="imqAddressList">qa30-vm:7676</prop>
<prop key="imqReconnectAttempts">-1</prop>
</props>
</property>
</bean>
<bean id="connectionfactory"
factory-bean="connectionfactoryfactory"
factory-method="constructConnectionFactory"/>
<bean id="jmsFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="connectionfactory" />
</bean>
来源:https://stackoverflow.com/questions/6171457/accessing-openmq-remotely