.replyToQueueManagerName and replyToQueueName on d

2019-04-16 12:51发布

问题:

How do I go about if my replyToQueueManagerName and replyToQueueName is not in the same MQEnvironment as my requestQueueuManagerName and requestQueueName?

Example:

//MQEnvironment for requestMessage
MQEnvironment.hostname = requestMessageHost;
MQEnvironment.channel = requestMessageChannel;
MQEnvironment.port = requestMessagePort

MQQueueManager qMgr = new MQQueueManager(requestQueueuManagerName);

MQQueue inputQueue = qMgr.accessQueue(requestQueueName,MQC.MQOO_OUTPUT);

MQMessage requestMessage = new MQMessage();
MQPutMessageOptions pmo = new MQPutMessageOptions();

requestMessage.writeString(sampleXmlRequest);
requestMessage.replyToQueueManagerName = replyToQueueManagerName;
requestMessage.replyToQueueName = replyToQueueName; 

In VB.NET one can connect to QueueManagers and Queues that reside on different environments.

回答1:

I am assuming you are asking how to connect to another queue manager when MQEnvironment is already used for connecting to a queue manager.

You can create a connection to a queue manager by providing connection information through a hash table. This piece of code is in C#.

       Hashtable mqProps = new Hashtable();
       mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
       mqProps.Add(MQC.HOST_NAME_PROPERTY, "<yourhost>");
       mqProps.Add(MQC.PORT_PROPERTY, port);
       mqProps.Add(MQC.CHANNEL_PROPERTY, "<svrconn channel name>");

       MQQueueManager qmConn = new MQQueueManager("replyQM", mqProps);

Here is the Java code:

      Hashtable<String, Object> properties;
      properties = new Hashtable<String, Object>();
      properties.put("hostname", "replyqmhost");
      properties.put("port", new Integer(1414));
      properties.put("channel", "REPLYQM.SVRCONN");
      properties.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY,true);
      properties.put(MQConstants.USER_ID_PROPERTY, "<user id>");
      properties.put(MQConstants.PASSWORD_PROPERTY, "<password>");

      /**
        * Connect to a queue manager 
        */
      MQQueueManager queueManager = new MQQueueManager("replyQM", properties);


回答2:

While it is true that Shashi's answer shows you how to connect to two different queue manager's in one application, this is not normally the way to handle a ReplyToQ on another queue manager. It will almost always be the case that the ReplyToQ/ReplyToQMgr is on another queue manager. But you should have channels and a transmission queue to take that message back to the ReplyToQMgr and just do the put of the reply message to the same queue manager that you did the get of the request message from.

This has a number of advantages

  • Your getting of the response message and put of the reply message can be in the same MQ transaction
  • You are not tied to the availability of the remote queue manager in order to process the message and put the reply
  • Your application does not need to be aware of the location of the remote queue manager, this can be handled by the queue manager administrator
  • Handling ReplyToQMgrs in this way also continues to be viable as you get more requests in from different queue managers, connecting to each one in your application directly would soon get messy, and have you application needing too much knowledge of the network.


标签: java ibm-mq