我使用 JavaEE 8 在 liberty 18.0.0.2 上工作。
我创建了这样的自定义 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 +
'}';
}
}
如何按对象属性选择队列?
这是我的代码,但不起作用:
JMSConsumer consumer = context.createConsumer(destination, "destination='abcdefg'");
Message message = consumer.receiveNoWait();
if (message != null) {
MyTextMessage myTextMessage = message.getBody(MyTextMessage.class);
System.out.println(myTextMessage);
}