简体   繁体   English

对象消息上的JMS消息选择器

[英]JMS message selector on Object message

I working on liberty 18.0.0.2 with JavaEE 8 . 我使用JavaEE 8开发自由18.0.0.2。
I created Custom jms object message like this : 我创建了自定义jms对象消息,如下所示:

public class MyTextMessage extends implements Serializable {
    private String text;
    private String destination;
    private LocalDateTime dateTime;

    public MyTextMessage(String text, String destination, LocalDateTime dateTime) {
        this.text = text;
        this.destination = destination;
        this.dateTime = dateTime;
    }

    public MyTextMessage() {
    }

    // Getter and Setter 

    @Override
    public String toString() {
        return "MyTextMessage{" +
                "text='" + text + '\'' +
                ", destination='" + destination + '\'' +
                ", dateTime=" + dateTime +
                '}';
    }
}

How can select on queue by object property ? 如何按对象属性选择队列?
this is my code but not work : 这是我的代码但不起作用:

JMSConsumer consumer = context.createConsumer(destination, "destination='abcdefg'");
 Message message = consumer.receiveNoWait();
 if (message != null) {
      MyTextMessage myTextMessage = message.getBody(MyTextMessage.class);
      System.out.println(myTextMessage);
 }    

You're trying to select on the property of an ObjectMessage implementation which is technically part of the body of the message. 您正在尝试选择ObjectMessage实现的属性,该实现在技术上是消息正文的一部分。 However, section 3.8.1 of the JMS 2 specification states: 但是,JMS 2规范的3.8.1节规定:

Message selectors cannot reference message body values. 消息选择器无法引用消息体值。

A message selector matches a message when the selector evaluates to true when the message's header field and property values are substituted for their corresponding identifiers in the selector. 当消息的头字段和属性值替换为选择器中的相应标识符时,消息选择器在选择器的计算结果为true时匹配消息。

Therefore, you need to set a property on the message with a value you can select on (eg using javax.jms.Message.setStringProperty("destination", "abcdefg") ). 因此,您需要在消息上设置一个属性,您可以选择一个值(例如,使用javax.jms.Message.setStringProperty(“destination”,“abcdefg”) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM