我正在尝试使用Payara 4实现Queue JMS Producer和Consumer。我在Payara 4中创建了JMS资源。下面是我的JMS连接工厂和队列资源
jms/testConnectionFactory
jms/testQueue
这是我的JMS发件人代码
@Stateless
public class JMSSender {
@Inject
Logger logger;
@Resource(lookup = "jms/testQueue")
Queue queue;
@Inject
@JMSConnectionFactory("jms/testConnectionFactory")
JMSContext jmsContext;
public void createPerson(Person person) {
this.logger.log(Level.INFO, "Start to send message into JMS Queue");
this.logger.log(Level.INFO, "Create Person: " + person.toString());
jmsContext.createProducer().send(queue, person);
this.logger.log(Level.INFO, "Finish send message to JMS Queue");
}
}
然后这是我的JMS接收器代码
public class JMSReceiver {
@Inject
Logger logger;
@Resource(lookup = "jms/testQueue")
Queue queue;
@Inject
@JMSConnectionFactory("jms/testConnectionFactory")
JMSContext jmsContext;
public void receiveMessage() {
this.logger.log(Level.INFO, "Start to receive message from JMS Queue");
try {
JMSConsumer receiver = jmsContext.createConsumer(queue);
Person person = receiver.receiveBody(Person.class, 1000);
this.logger.log(Level.INFO, person.toString());
} catch(JMSRuntimeException e) {
this.logger.log(Level.WARNING, e.getMessage());
}
this.logger.log(Level.INFO, "End receive message from JMS Queue");
}
}
问题是,我无法使用上面的JMSReceiver
代码获取消息,并且没有错误。我尝试过使用 Message Driveb Bean (MDB)并且它正常工作。
我是JMS的新手,我无法弄清楚我的JMSReceiver
代码有什么问题导致它无法收到消息?