简体   繁体   English

通过绑定将JMS连接到远程MQ

[英]JMS connection to a remote MQ with bindings

I want to configure a Java application to work with a JMS IBM MQ queue using the bindings file. 我想配置Java应用程序以使用绑定文件与JMS IBM MQ队列一起使用。 I am using the JMSDEMO application provided by IBM. 我正在使用IBM提供的JMSDEMO应用程序。 It works with a local MQ manager but I cannot make it connect to a remote one. 它与本地MQ管理器一起工作,但是我无法使其连接到远程管理器。 I've generated the bindings file on the remote machine and copied it to my machine. 我已经在远程计算机上生成了绑定文件,并将其复制到我的计算机上。

I've changed the "localhost" in the bindings file to the remote machine name. 我已将绑定文件中的“ localhost”更改为远程计算机名称。 However, the app still thinks it should connect to a local QM. 但是,该应用程序仍然认为它应该连接到本地质量管理。 (actually it ignores the hostname settings). (实际上,它会忽略主机名设置)。

Here's the IBM demo code: 这是IBM演示代码:

public static final String     cfLookup    = "JMSDEMOCF";
public static final String     JNDITopic   = "JMSDEMOTopic";
public static final String     JNDIQueue   = "JMSDEMOQueue";
public static final String     icf     ="com.sun.jndi.fscontext.RefFSContextFactory";

........ ........

static              String     url         = "file:C:\\JMSDEMO\\JNDI";

.......... ..........

  Hashtable environment = new Hashtable();
  environment.put(Context.INITIAL_CONTEXT_FACTORY, icf);
  environment.put(Context.PROVIDER_URL, url);
  ctx = new InitialDirContext( environment );


  connFactory = (ConnectionFactory)ctx.lookup( cfLookup );


  connection = connFactory.createConnection();
  connection.start();

Here are some fragments of the bindings file (JMSDEMOCF is the name of the connection factory) 这是绑定文件的一些片段(JMSDEMOCF是连接工厂的名称)

JMSDEMOCF/RefAddr/3/Content=<the remote machine name or IP; both ignored>
JMSDEMOCF/RefAddr/29/Content=<the remote machine name or IP; both ignored>(the remote port)

It also has the following line: 它还具有以下行:

JMSDEMOCF/RefAddr/116/Type=XMSC_WMQ_LOCAL_ADDRESS

but deleting it changes nothing. 但是删除它不会改变任何东西。

Create a new connection factory in your "bindings file" with MQ Explorer (why are you trying to edit the file by hand?), and specify the Transport option as MQ Client on this new connection factory (the default is Bindings, which is the local connection mode). 使用MQ Explorer在“绑定文件”中创建一个新的连接工厂(为什么要尝试手动编辑文件?),并在此新的连接工厂上将Transport选项指定为MQ Client(默认为Bindings,即本地连接模式)。 On the Connection tab specify the address of the QM, and on the Channels tab the server connection channel to be used to connect to the QM. 在“连接”选项卡上,指定QM的地址,在“通道”选项卡上,指定用于连接到QM的服务器连接通道。

Use the new connection factory in your application when connecting from a remote host. 从远程主机连接时,请在应用程序中使用新的连接工厂。 You may need to include some additional MQ JARs in the classpath. 您可能需要在类路径中包括一些其他的MQ JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM