Java 使用 jms 连接到 ibm mq。指定通道和队列管理器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2319143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect to ibm mq with jms . Specify the channel and queue manager
提问by bhargav
How do i specify which queue manager to connect to in my system properties. Here is the code:
如何在系统属性中指定要连接到的队列管理器。这是代码:
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial", "com.ibm.mq.jms.context.WMQInitialContextFactory");
properties.setProperty("java.naming.provider.url", "localhost:1414/SYSTEM.DEF.SVRCONN");
Context context = new InitialContext(properties);
factory= (QueueConnectionFactory)context.lookup("TESTOUT");
context always gets TEST que only not able to connect to TESTOUT queue
上下文总是得到 TEST 队列,但无法连接到 TESTOUT 队列
回答by SOA Nerd
Here's an example from the IBM website about how to setup Websphere Application Server (WAS) to use MQ as the mechanism for JMS.
http://www.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html
以下是来自 IBM 网站的一个示例,该示例介绍如何设置 Websphere Application Server (WAS) 以使用 MQ 作为 JMS 的机制。
http://www.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html
Also IBM has a good redbook that outlines examples for how to do this if you are the message producer at:
http://www.redbooks.ibm.com/redbooks/pdfs/sg247128.pdf
如果您是消息生产者,IBM 也有一本很好的红皮书,其中概述了如何执行此操作的示例:http:
//www.redbooks.ibm.com/redbooks/pdfs/sg247128.pdf
There is also some good Java code examples at:
http://www.capitalware.biz/mq_code_java.html
还有一些很好的 Java 代码示例:http:
//www.capitalware.biz/mq_code_java.html
Sorry....I don't have access to the code I did for this anymore or I'd give you some of my examples.
抱歉......我无法访问我为此所做的代码,或者我会给你一些我的例子。
回答by Dr. Xray
One can use the constructor of MQQueueManager to specify the name of the target queue manager, use the one with properties for connection information. Refer the following link for more details on properties:
可以使用 MQQueueManager 的构造函数来指定目标队列管理器的名称,使用带有属性的连接信息。有关属性的更多详细信息,请参阅以下链接:
回答by T.Rob
Hmmm...so many issues with the code snippet you posted, hard to know where to start.
嗯......你发布的代码片段有很多问题,很难知道从哪里开始。
Using the WMQInitialContectFactory does not seem like the place to start with MQ. It adds a layer of complexity you probably don't want at this stage. I'd suggest using Sun's fscontext and keep the managed objects in a local file. The initial context you are using is primarily used to make a shared JNDI repository for many users or applications, however it's not supported. My issue with it is that the program first has to connect to the queue manager in order to get a connection factory which...tells the program how to connect to the QMgr!
使用 WMQInitialContectFactory 似乎不是从 MQ 开始的地方。它增加了一层您在这个阶段可能不想要的复杂性。我建议使用 Sun 的 fscontext 并将托管对象保存在本地文件中。您使用的初始上下文主要用于为许多用户或应用程序创建共享 JNDI 存储库,但它不受支持。我的问题是程序首先必须连接到队列管理器才能获得一个连接工厂......告诉程序如何连接到 QMgr!
All those objects named SYSTEM.DEF.* or SYSTEM.AUTO.* should never be used for actual connections. They are templates that new objects inherit from. If they are useable you can't secure them or any objects created from them.
所有这些名为 SYSTEM.DEF.* 或 SYSTEM.AUTO.* 的对象都不应用于实际连接。它们是新对象继承自的模板。如果它们可用,您将无法保护它们或从它们创建的任何对象。
Either the snippet is incomplete or you are confusing the connection factory with the queue object. The post says you want the TESTOUT queue but the code has only a queue connection factory and no destination or queue object.
片段不完整,或者您将连接工厂与队列对象混淆。帖子说你想要 TESTOUT 队列,但代码只有一个队列连接工厂,没有目标或队列对象。
If you've installed WMQ server or client locally, you already have a bunch of good samples. The default location for these is C:\Program Files\IBM\WebSphere MQ\tools\jms\samples and they include both pub/sub and point-to-point examples. If you want an example that demonstrates creating the .bindings file, check out the article and sample code here: http://www.ibm.com/developerworks/websphere/techjournal/0610_woolf/0610_woolf.htmlThe article explains some of the issues I just mentioned with the channels, client security, etc.
如果您已经在本地安装了 WMQ 服务器或客户端,那么您已经拥有了一堆很好的示例。它们的默认位置是 C:\Program Files\IBM\WebSphere MQ\tools\jms\samples,它们包括发布/订阅和点对点示例。如果您想要一个演示如何创建 .bindings 文件的示例,请查看这里的文章和示例代码:http: //www.ibm.com/developerworks/websphere/techjournal/0610_woolf/0610_woolf.html文章解释了一些问题我刚刚提到了渠道、客户安全等。