我正在使用JavaEE 8和Liberty 18.0.0.2进行工作。
我创建了一个自定义的JMS对象消息,如下所示:
public class MyTextMessage 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 +
'}';
}
}
如何通过对象属性在队列上进行选择?以下是我的代码,但无法正常工作:
JMSConsumer consumer = context.createConsumer(destination, "destination='abcdefg'");
Message message = consumer.receiveNoWait();
if (message != null) {
MyTextMessage myTextMessage = message.getBody(MyTextMessage.class);
System.out.println(myTextMessage);
}