远程访问OpenMQ [英] Accessing OpenMQ remotely

查看:135
本文介绍了远程访问OpenMQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地安装了openMQ,它运行正常。我使用以下代码使用JNDI查找获取 QueueConnectionFactory

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

以上内容返回连接工厂,我也从那里访问 replyQueue requestQueue

The above returns me the connection factory from where I also access the replyQueue and requestQueue.

这是我设置队列的方式

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"

我的问题是:


  1. 我该怎么办? linux
    服务器上的etup openMQ,这样我就可以从一个不同的服务器访问openMQ
    ,其中
    代码将在tomcat
    apache服务器(也是一个linux盒子)中运行。

  1. 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).

我需要对
进行哪些更改才能获得
QueueConnectionFactory 来自openMQ

坐在不同的服务器上?

What changes will I have to make to the code to get the
QueueConnectionFactory from openMQ
sitting on a different server ?

我'我没有在GlassFish中运行openMQ,我正在自己运行openMQ(imqbrokerd.exe)。

I'm not running openMQ in GlassFish, I'm running openMQ on it's own (imqbrokerd.exe).

推荐答案

在我的所有挖掘工作中,我没有发现任何迹象表明OpenMQ在单独使用时提供了JNDI提供程序。它看起来像是由GlassFish提供的。这意味着你需要使用类似LDAP的东西作为对象存储,我还没有这样做。

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.

目前我已经通过复制来欺骗了。绑定文件(在您的情况下位于c:\objectstore中)到JMeter可以看到的文件系统,以便我可以引用它。只要您使用实际的计算机名称或IP,而不是本地主机,它将起作用,但显然不会将其切割为生产。

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.

在Java方面你可以完全删除JNDI并直接实例化 com.sun.messaging.ConnectionFactory 。我用Spring注入了连接工厂。请注意,我必须包含我自己的一个非常简单的OpenMQConnectionFactoryFactory(从 https://wikis.oracle中窃取)。 com / display / GlassFish / OpenMQSpringConnectionConsumer )因为com.sun.messaging.ConnectionFactory不是bean。

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>



这篇关于远程访问OpenMQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆