Cannot set the property value for JMS_IBM_MQMD_MsgId in weblogic, JMS, java

那年仲夏 提交于 2019-12-13 16:19:10

问题


I want to send a message to a JMS Queue, and I want to set an object property:

tMessage.setObjectProperty("JMS_IBM_MQMD_MsgId", bytes); //bytes is a byte array value

But I am getting an exception for this row:

tMessage.setObjectProperty("JMS_IBM_MQMD_MsgId", toByteArray((phone+"IBM").toCharArray()));

Why cannot I set byte array to this property? I saw some example, and everyone sets bytearray, but I am getting exception:

weblogic.jms.common.MessageFormatException: [JMSClientExceptions:055123]Invalid property value, [B@48647dd0

Why? Thank you!


回答1:


For setObjectProperty:

The setObjectProperty method accepts values of class Boolean, Byte, Short, Integer, Long, Float, Double, and String. An attempt to use any other class must throw a JMSException.

So it does not accept ByteArray. setObjectProperty accepts Object so you don't get compile error.




回答2:


I'd suggest having a look at one of the samples in the WMQ installation - called SimpleWMQMDWrite.java

This does use setObjectProperty as follows:

  // Generate a custom message id
  byte[] customMessageId = new byte[24];
  for (int i = 0; i < 24; i++) {
    // Hex-string 010203040506070801020304050607080102030405060708
    customMessageId[i] = (byte) ((i % 8) + 1);
  }

  // Write to MQMD.MsgId via JMS_IBM_MQMD_MSGID message property
  message.setObjectProperty(WMQConstants.JMS_IBM_MQMD_MSGID, customMessageId);

The error message you've included though doesn't look much like a WMQ JMS error message more WebLogic, wonder if that has wrapped the message object and is doing some additional checking?

M.




回答3:


Also you can transform your hex string to byte array using com.ibm.msg.client.commonservices.Utils.hexToBytes(yourHexString)



来源:https://stackoverflow.com/questions/19835743/cannot-set-the-property-value-for-jms-ibm-mqmd-msgid-in-weblogic-jms-java

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