设置邮件头时出现MQ错误

时间:2015-03-09 19:36:09

标签: java ibm-mq

我正在尝试在MQ消息上设置自定义标头,但是当我这样做时,我得到一个MQException(2142),其中2195也写入StdErr。在下面的代码中,有一个mqMessage.setStringProperty的调用...如果我删除该行,这个代码可以工作。我想按照我在这里看到的内容:How to use JMS Properties on IBM MQ JMS Interface?

private MQQueueManager qm;
private MQQueue queue;

private void initialize() throws Exception {
    MQEnvironment.hostname = "myhost";
    MQEnvironment.port = 1234;
    MQEnvironment.channel = "channelname"; 

    qm = new MQQueueManager( "QMgrName" );
    queue = qm.accessQueue( 
                "QueueName", 
                CMQC.MQOO_OUTPUT | CMQC.MQOO_FAIL_IF_QUIESCING );
}

private void sendMessage() throws Exception {
    MQMessage mqMessage = new MQMessage();
    mqMessage.format = CMQC.MQFMT_STRING;
    mqMessage.messageId = CMQC.MQMI_NONE;

    MQPutMessageOptions pmo = new MQPutMessageOptions();
    pmo.options = CMQC.MQPMO_NO_SYNCPOINT;

    // The problem line
    mqMessage.setStringProperty("header.name", "value");

    mqMessage.writeString( "This is a test");
    queue.put(mqMessage, pmo);
}

1 个答案:

答案 0 :(得分:0)

问题是您的变量名称无效:

  

" header.name"

将其更改为headerName,它将起作用。