【问题标题】:Setting IBM MQ custom property in JMS doesn't work在 JMS 中设置 IBM MQ 定制属性不起作用
【发布时间】:2021-04-17 12:04:55
【问题描述】:

尝试在发送消息时在 JMS 中设置 IBM MQ 定制属性。它不起作用。

我正在 JMS/Apache camel 中寻找以下等效项。

mQMessage.setStringProperty( "customProperty", "123" );

尝试了以下 3 个选项:

1) exchange.getIn().setHeader( "customProperty", "123" );
2) exchange.getIn().setProperty( "customProperty", "123" );
3) mQQueueConnectionFactory.setStringProperty( "customProperty", "123" );

以下读取属性的代码会引发错误,因为该属性似乎不存在。 mQMessage.getStringProperty("messageGlobalSequenceNumber")

抛出以下错误:

com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2471'.
        at com.ibm.mq.MQMessage.getProperty(MQMessage.java:5694)
        at com.ibm.mq.MQMessage.getStringProperty(MQMessage.java:6949)
        at com.ibm.mq.MQMessage.getStringProperty(MQMessage.java:6925)
...

【问题讨论】:

    标签: java apache-camel jms ibm-mq


    【解决方案1】:

    您确定您尝试检索的属性确实存在于该消息中吗?因为原因代码 2471 (MQRC_PROPERTY_NOT_AVAILABLE) 明确表示指定的属性不存在。

    在JMS(针对IBM MQ)中创建消息属性的正确方法如下:

    /**
     * Send a message to a queue.
     * @param session
     * @param myQ
     * @throws JMSException
     */
    private void sendMsg(QueueSession session, Queue myQ) throws JMSException
    {
       QueueSender sender = null;
    
       try
       {
          TextMessage msg = session.createTextMessage();
          msg.setText("This is a test message.");
          msg.setStringProperty("MyProp01", "somevalue");
    
          sender = session.createSender(myQ);
          sender.send(msg);
       }
       finally
       {
          try
          {
             if (sender != null)
                sender.close();
          }
          catch (Exception ex)
          {
             System.out.println("sender.close() : " + ex.getLocalizedMessage());
          }
       }
    }
    

    您是否使用 MQ 工具检查消息的属性值?我运行了上面的代码,然后使用MQ Visual Edit 检查了队列中的消息,这是一个屏幕截图:

    或显示命名属性(又名消息属性)的已打开选定消息的屏幕截图:

    【讨论】:

    • 谢谢,我正在使用没有 JNDI 和 MQ Explorer 的 Apache camel JMS。从 JMS 正在设置它,我可以在那里看到它,但是当它到达 MQ 时它已经消失了。看到一些评论说我必须使用骆驼 jms 标头而不是骆驼标头。所以尝试设置 jmsComponent.setAllowAdditionalHeaders("customProp=12345");这也没有用,我已经没有办法尝试了。这篇文章说有一些财产,但我不知道是哪一个camel.465427.n5.nabble.com/…
    • 消息在MQ队列中时是否有任何消息属性?如果不是,那么您将 TARGCLIENT 设置为什么?见ibm.com/support/pages/node/465799
    • targetClient 设置为 1,当我设置为 0 时,我得到了 MQHRF2 标头中的标头。但我不知道如何在 MQMD 标头中设置它。试图设置 jmsComponent.setDestinationResolver,仍然没有运气。 });
    • 尝试在目标解析器中设置以下内容 mqQueueSession.setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true); mqQueueSession.setBooleanProperty(WMQ_MQMD_WRITE_ENABLED, true); mqQueueSession.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT,WMQConstants.WMQ_MDCTX_SET_ALL_CONTEXT ; mqQueueSession.setStringProperty("customProp", "abc"); return mqQueueSession.createQueue("queue:///" + destinationName + "?targetClient=1");跨度>
    • @Anu 最好在您的问题中编辑和添加此类详细信息。
    猜你喜欢
    • 2020-08-20
    • 2011-08-16
    • 2022-08-19
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多