简体   繁体   English

通过Java程序使用MQ客户端访问远程IBM MQ Server队列

[英]Access Remote IBM MQ Server Queue using MQ Client through a java program

I am relatively new to IBM MQ. 我对IBM MQ比较陌生。

My requirement is to connect to a Remote IBM MQ Server Queue through IBM MQ Client. 我的要求是通过IBM MQ Client连接到远程IBM MQ Server队列。 And then, access the queue through MQ Client using IBM MQ Java API. 然后,使用IBM MQ Java API通过MQ客户端访问队列。

Is this the right approach? 这是正确的方法吗?

I have already setup IBM MQ Server, IBM MQ Explorer on my local machine, created a Queue Manager, Queue. 我已经在本地计算机上设置了IBM MQ Server和IBM MQ Explorer,并创建了一个队列管理器Queue。 I have also written a Java program to connect to MQ using IBM MQ API. 我还编写了一个Java程序,以使用IBM MQ API连接到MQ。

This Java program has the following parameters: 此Java程序具有以下参数:

String queueManagerName = "QUEUE.MANAGER.1";
String userID = "";
String password = "";
String queueName = "QUEUE1";
String hostName = "localhost";
String channel = "CHANNEL1";
int port = 1414;

Here, everything seems to work fine. 在这里,一切似乎都正常。 I can send/receive messages from/to the MQ Server Queue through the Java program. 我可以通过Java程序从MQ服务器队列发送消息/从MQ服务器队列接收消息。

Now, I have installed IBM MQ Client on the same machine, how do I connect to the same Server Queue using the java program through the MQ Client? 现在,我已经在同一台机器上安装了IBM MQ Client,如何通过MQ Client使用java程序连接到同一服务器队列?

My requirement is to have: 我的要求是:

  1. MQ Server running on a different machine. 在另一台机器上运行的MQ Server。
  2. Connect to the Server Queue using the MQ Client installed on local machine. 使用安装在本地计算机上的MQ客户端连接到服务器队列。
  3. The java program should Send/Receive messages to the Server Queue through the local MQ Client. Java程序应通过本地MQ客户端向服务器队列发送/接收消息。

How, can I achieve this? 我怎样才能做到这一点?

You will need to point connection parameters for your application to connect to queue manager on remote machine. 您将需要为应用程序指定连接参数,以连接到远程计算机上的队列管理器。 For example: 例如:

String queueManagerName = "<Remote queue manager name>";
String userID = "<valid user existing on remote machine>";
String password = "<password for user>";
String hostName = "<remote host name>";
String channel = "<Channel name on remote queue manager>";
int port = <port number where queue manager is listening>;

But you will need to configure authentication and authorization on remote queue manager for application to connect. 但是您将需要在远程队列管理器上配置身份验证和授权,以使应用程序连接。 If that is not configured, then you will get MQRC 2035 - NOT_AUTHORIZED errors. 如果未配置,则将收到MQRC 2035-NOT_AUTHORIZED错误。

String mqHost = null; // Hostname
String mqPort = null; // Port
String mqChannel = null; // Channel 
String mqQMgr = null;   // Queue Manager
MQQueueManager qMgr = null;
MQEnvironment.hostname = mqHost;
MQEnvironment.port = Integer.valueOf(mqPort).intValue();
MQEnvironment.channel = mqChannel;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQEnvironment.userID = "USERID";

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

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