需要将标题添加到将发送到IBM MQ Websphere的消息中 [英] need to add header to message which will be sent to IBM MQ websphere

查看:274
本文介绍了需要将标题添加到将发送到IBM MQ Websphere的消息中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何向我们发送到IBM MQ Websphere服务器的消息中添加消息头.下面是我尝试使用的代码,但出现异常:

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 :

创建与服务器的连接

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

发送消息

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);

但是我得到了异常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.

推荐答案

为什么要将Java SE MQ API调用与JMS调用混合使用?

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

在手册中,针对Java的WebSphere MQ类的处理消息属性"部分:

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

用于处理消息句柄的函数调用中没有等效项 Java的WebSphere MQ类.设置,返回或删除消息 处理属性,请使用MQMessage类的方法.

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);

最后一点请注意,因为您正在使用WMQ v6,所以请不要回复说您无法做到这一点. WMQ v6大约2年前就不再支持,因此您必须升级到WMQ v7.*(最好是WMQ v7.5).

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).

这篇关于需要将标题添加到将发送到IBM MQ Websphere的消息中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆