ibm mq 收发消息 java,如何使用java程序为IBM MQ设置消息ID

I am able to set correlation id for IBM mq but unable to set message id for the message the message id I am setting is being overridden by the MQ how to set this message id below one is the code I am trying please help me on this task. Is there any thing I need do in the code???

public static void main(String args[])

{

try{

MQQueueConnectionFactory cf = new MQQueueConnectionFactory();

cf.setHostName("xxx");

cf.setPort(4444);

cf.setTransportType(1);

cf.setQueueManager("xxxx");

cf.setChannel("CLIENT.xyZ");

MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();

MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

MQQueue queue = (MQQueue) session.createQueue("WW.ESB.ENTRY.SERVICE.IN");

queue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);

queue.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);

MQQueueSender sender = (MQQueueSender) session.createSender(queue);

true);

File f=new File("C:/InputPayloads/Payloads/test4.xml");

JMSTextMessage message = (JMSTextMessage) session.createTextMessage(FileUtils.readFileToString(f));

message.setStringProperty("JMS_IBM_MQMD_UserIdentifier", "avada2");

// Hex-string 010203040506070801020304050607080102030405060708

byte[] customMessageId = new byte[24];

for (int i = 0; i < 24; i++) {

customMessageId[i] = (byte) ((i % 8) + 1);

}

message.setObjectProperty(WMQConstants.JMS_IBM_MQMD_MSGID, customMessageId);

message.setStringProperty("xxx", "SH_TEST04");

message.setStringProperty("yyy", "JP");

message.setStringProperty("zzz", "1");

connection.start();

System.out.println("before Sent message:\\n" + message);

sender.send(message);

System.out.println("Sent message:\\n" + message);

sender.close();

session.close();

connection.close();

}catch(Exception e)

{

System.out.println(e);

}

}

}

I am getting below error

com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2008: Failed to open MQ queue 'WW.zzz.xxx.yyy.zz'.

JMS attempted to perform an MQOPEN, but IBM MQ reported an error.

Use the linked exception to determine the cause of this error. Check that the specified queue and queue manager are defined correctly.

due to this line

解决方案

The JMS Spec indicates that the message ID must be set by the JMS provider and that it must either be unique or null, i.e. you can't set it yourself.

However, you can use an IBM MQ specific extension to set the Message ID yourself, bearing in mind that you are now breaking the JMS Spec.

To do so, you need to set JMS_IBM_MQMD_MsgId, whose value is then copied into JMSMessageID (i.e. you can't set it directly).

Now you know the name of the attribute to set, see this other question for more details and a code example in an answer from an IBM MQ JMS expert (@Calanais).

Further reading

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值