简体   繁体   中英

JMS message selector on Object message

I working on liberty 18.0.0.2 with JavaEE 8 .
I created Custom jms object message like this :

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. However, section 3.8.1 of the JMS 2 specification states:

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.

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") ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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