JMS 连接到具有绑定的远程 MQ

JMS connection to a remote MQ with bindings

我想配置 Java 应用程序以使用绑定文件与 JMS IBM MQ 队列一起工作。 我正在使用 IBM 提供的 JMSDEMO 应用程序。 它与本地 MQ 管理器一起工作,但我无法使其连接到远程管理器。 我已经在远程机器上生成了绑定文件并将其复制到我的机器上。

我已将绑定文件中的 "localhost" 更改为远程机器名称。 但是,该应用程序仍然认为它应该连接到本地 QM。 (实际上它忽略了主机名设置)。

这是 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();

这里是绑定文件的一些片段(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)

它还有下面一行:

JMSDEMOCF/RefAddr/116/Type=XMSC_WMQ_LOCAL_ADDRESS

但删除它没有任何改变。

使用 MQ Explorer 在 "bindings file" 中创建一个新的连接工厂(您为什么要尝试手动编辑文件?),并在这个新的连接工厂(默认设置)上将传输选项指定为 MQ 客户端是Bindings,也就是本地连接方式)。 在“连接”选项卡上指定 QM 的地址,在“通道”选项卡上指定用于连接到 QM 的服务器连接通道。

从远程主机连接时,在您的应用程序中使用新的连接工厂。您可能需要在类路径中包含一些额外的 MQ JAR。