如何在IBM MQ JMS接口上使用JMS属性? [英] How to use JMS Properties on IBM MQ JMS Interface?

查看:362
本文介绍了如何在IBM MQ JMS接口上使用JMS属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有MQ 6.0.2.的MQ JMS接口.

似乎仅支持预定义的属性,而不支持任意属性. 例如,我可以正确地getJMSCorrelationID()getJMSPriority()等.但是,当我在发送方上设置任意属性时:

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

我无法从接收方的消息中获取该属性:

message.getStringProperty("my arbitrary name");

我只是得到null.

有没有一种方法可以像在任何JMS实现中那样执行,还是MQ JMS的局限性?

解决方案

如果具有完整的客户端安装,则可以转到C:\Program Files\IBM\WebSphere MQ\tools\jms\samples\interactive\/opt/mqm/samp中的某个位置,然后查找SampleConsumerJava.javaSampleProducerJava.java. /p>

从示例Producer程序中:

  // Set custom properties
  msg.setStringProperty("MyStringProperty", "My Year Of Birth");
  msg.setIntProperty("MyIntProperty", 2007);

并且来自样本消费者:

  // 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]");

属性名称遵循Java变量名称的规则,并且不能包含空格.

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.

这篇关于如何在IBM MQ JMS接口上使用JMS属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆