how to send msg to Websphere MQ with specific reply to MQ MGR using JMS

谁说我不能喝 提交于 2019-12-06 15:50:32

Try this:-

MQQueue replyToQ = new MQQueue(QMgrName, ReplyQueue);
Destination replyTo = (Destination) replyToQ;
message.setJMSReplyTo(replyTo);
Ravi123
public void postMessageToDatastage(String msg,String queueName,String batchID){

    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT; 
    try {
        defaultLocalQueue = qManager.accessQueue(queueName, openOptions);            
        MQMessage putMessage = new MQMessage();
        putMessage.writeUTF(msg);            
        //specify the message options...
        MQPutMessageOptions pmo = new MQPutMessageOptions(); 
        // accept 
        // put the message on the queue
        defaultLocalQueue.put(putMessage, pmo);            
        System.out.println("Message is put on MQ.");
        //System.out.println("Queue is closing...");
         defaultLocalQueue.close();
         // for asynchornus communtication...
        //MQAsyncStatus asyncStatus = qManager.getAsyncStatus();
          qManager.disconnect();

    } catch (MQException e) {
        e.printStackTrace();
    }
}

public void init(){

    //Set MQ connection credentials to MQ Envorinment.
     MQEnvironment.hostname = hostName;
     MQEnvironment.channel = channel;
     MQEnvironment.port = port;
     MQEnvironment.userID = user;
     MQEnvironment.password = password;
     //set transport properties.
     MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);

     try {
         //initialize MQ manager.
        qManager = new MQQueueManager(qMngrStr);
    } catch (MQException e) {
        e.printStackTrace();
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!