[英]ActiveMQ 5.10 client in Tomcat 7 with InitialDirContext
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. 我正在使用一个现有的Web应用程序(在Tomcat 7.0.26中运行),该应用程序通常通过JMS API通过IBM WebsphereMQ与外部系统进行通信。 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. 我现在正在尝试使它与ActiveMQ 5.10客户端库一起使用。 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 to com.sun.jndi.fscontext.RefFSContextFactory
initialContextFactory
始终设置为com.sun.jndi.fscontext.RefFSContextFactory
providerURL
is currently set to a file://C:/directory
URL, pointing to a .bindings
file as generated by "Managed JMS Objects" from WebsphereMQ Explorer providerURL
当前设置为file://C:/directory
URL,指向由WebsphereMQ Explorer的“ Managed JMS Objects”生成的.bindings
文件 requestQueueName
& responseQueueName
requestQueueName
和responseQueueName
I'm now changing initialContextFactory
to org.apache.activemq.jndi.ActiveMQInitialContextFactory
, and providerURL
to tcp://localhost:61616
. 我现在将
initialContextFactory
更改为org.apache.activemq.jndi.ActiveMQInitialContextFactory
,并将providerURL
更改为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.
我在ActiveMQ Web管理控制台中看不到任何连接。
Researching on the web, I see that normally ActiveMQ JNDI with Tomcat is set up differently: 在网络上进行研究,我发现通常使用Tomcat的ActiveMQ JNDI的设置是不同的:
Resource
entries in context.xml Resource
条目 new InitialContext();
new InitialContext();
envContext = (Context) initCtx.lookup("java:comp/env");
envContext = (Context) initCtx.lookup("java:comp/env");
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). 我如何从
InitialDirContext
实例获取ActiveMQ QueueConnectionFactory / Queue对象,仅使用INITIAL_CONTEXT_FACTORY和PROVIDER_URL进行初始化,并且大概在Tomcat端没有任何其他配置(尽管如有必要,我也可以选择更改tomcat配置)。
Maarten 马腾
Turns out I needed to include geronimo-j2ee-management_1.1_spec-1.0.1.jar into the CLASSPATH of this application as well. 原来,我还需要将geronimo-j2ee-management_1.1_spec-1.0.1.jar包含到此应用程序的CLASSPATH中。 Without this, an exception was thrown that wasn't logged anywhere, so it took some ingenuity to figure that one out.
没有这一点,就会抛出一个异常,该异常未在任何地方记录,因此需要一些技巧才能弄清楚该异常。
Maarten 马腾
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.