java jms接口,如何在IBM MQ JMS接口上使用JMS属性?

I'm using MQ JMS interface with MQ 6.0.2.

It seems that only pre defined properties are suported and not arbitrary ones.

for instance, I can properly getJMSCorrelationID(), getJMSPriority() etc. However, when i set an arbitrary property on the sender:

message.setStringProperty("my arbitrary name", "value");

I can't get the property from the message on the receiver:

message.getStringProperty("my arbitrary name");

I simply get null.

Is there a way to do that as in any JMS implementation, or is that an MQ JMS limitation?

解决方案

If you have the complete client install, you can go to C:\Program Files\IBM\WebSphere MQ\tools\jms\samples\interactive\ or somewhere in /opt/mqm/samp and look for SampleConsumerJava.java and SampleProducerJava.java.

From the sample Producer program:

// Set custom properties

msg.setStringProperty("MyStringProperty", "My Year Of Birth");

msg.setIntProperty("MyIntProperty", 2007);

And from the sample Consumer:

// Get values for custom properties, if available

String property1 = msg.getStringProperty("MyStringProperty");

// Get value for an int property, store the result in long to validate

// the get operation.

long property2 = ((long) Integer.MAX_VALUE) + 1;

property2 = msg.getIntProperty("MyIntProperty");

if ((property1 != null) && (property2 < Integer.MAX_VALUE)) {

System.out.println("[Message has my custom properties]");

Property names follow the rules for Java variable names and cant have spaces in them.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值