need to add header to message which will be sent to IBM MQ websphere

浪尽此生 提交于 2019-12-08 13:11:22

问题


I am not sure how to add message header to the message which we send to IBM MQ websphere server. Below is code I tried to use but I get exception :

Creating Connection to the server

        qMgr = new MQQueueManager(queueMgr, props);

        int openOptions = MQC.MQOO_INPUT_AS_Q_DEF
                | MQC.MQOO_OUTPUT |  MQC.MQOO_INQUIRE;
        queue = qMgr.accessQueue(queueName, openOptions);
        message = new MQMessage();

Sending the Message

public String sendMessage(){

      MQPutMessageOptions pmo = new MQPutMessageOptions();


        message.format                  = MQC.MQFMT_STRING;
        message.feedback                = MQC.MQFB_NONE;
        message.messageType             = MQC.MQMT_DATAGRAM;

        message.messageId     = MQC.MQMI_NONE;
        message.correlationId = MQC.MQCI_NONE;

            message.writeString(sMsg);
            queue.put(message,pmo);
}

I tried with the below code to add Header

((TextMessage)message).setStringProperty(header_name,header_value);

But i get the exception java.lang.ClassCastException: com.ibm.mq.MQMessage cannot be cast to javax.jms.TextMessage.

And I am Stuck here. If this is solved then the riddle is completed.


回答1:


Why are you mixing Java SE MQ API calls with JMS calls?

From the manual, in the section 'Handling message properties' for WebSphere MQ classes for Java:

Function calls to process message handles have no equivalent in WebSphere MQ classes for Java. To set, return, or delete message handle properties, use methods of the MQMessage class.

Therefore, why aren't you simply doing:

MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_FAIL_IF_QUIESCING | MQC.MQPMO_NO_SYNCPOINT;

message.format        = MQC.MQFMT_STRING;
message.feedback      = MQC.MQFB_NONE;
message.messageType   = MQC.MQMT_DATAGRAM;
message.messageId     = MQC.MQMI_NONE;
message.correlationId = MQC.MQCI_NONE;

message.setStringProperty(header_name,header_value)

message.writeString(sMsg);
queue.put(message,pmo);

One final note, please do not reply saying you can't do that, as you are using WMQ v6. WMQ v6 went out of support almost 2 years ago, so you must upgrade to WMQ v7.* (preferably to WMQ v7.5).



来源:https://stackoverflow.com/questions/23557820/need-to-add-header-to-message-which-will-be-sent-to-ibm-mq-websphere

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!