标题可能令人困惑但这是我想要完成的。我想从1 ejb向另一个发送一条jms消息,第二个ejb有一个消息监听器,现在它正常工作。但我希望第一个ejb创建一个临时目标队列,第二个ejb将响应 - 这也正常工作。
我的问题出现在第二个ejb中,它正在调用第三方Web服务,在某些情况下会在很长一段时间后响应,并且临时队列应该在该时间到期。但问题是它不符合java.net:http://java.net/projects/mq/lists/users/archive/2011-07/message/22
The message hasn't been delivered to a client and it expires -- in this case, the message is deleted when TTL is up.
The message is delivered to the JMS client (it's in-flight). Once this happens, since control is handed to the jms client, the broker cannot expire the message.
Finally, the jms client will check TTL just before it gives the message to the user application. If it's expired, we will not give it to the application and it will send a control message back to the broker indicating that the message was expired and not delivered.
所以,收到了但尚无回复。然后在它写入临时队列的时间它应该已经过期但由于某种原因我仍然能够写入队列并且我的imq日志中有ff:
1 messages not expired from destination jmsXXXQueue [Queue] because they have been delivered to client at time of the last expiration reaping
是否有其他实现我可以检测临时队列是否已经过期?这样我可以执行另一组操作?因为我现在的问题是ejb2响应较晚,而且ejb1没有更多的jms阅读器,因为它已经消失了。
答案 0 :(得分:0)
它现在有效,我的解决方案是在bean管理事务中包装第一个无状态bean(第一个jms消息源自的bean)。请参阅以下代码:
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
public class MyBean {
public void startProcess() {
Destination replyQueue = send(jmsUtil, actionDTO);
responseDTO = readReply(jmsUtil, replyQueue, actionDTO);
jmsUtil.dispose();
}
public Destination send(JmsSessionUtil jmsUtil, SalesOrderActionDTO soDTO) {
try {
utx.begin();
jmsUtil.send(soDTO, null, 0L, 1,
Long.parseLong(configBean.getProperty("jms.payrequest.timetolive")), true);
utx.commit();
return jmsUtil.getReplyQueue();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
}
}
return null;
}
public ResponseDTO readReply(JmsSessionUtil jmsUtil, Destination replyQueue,
SalesOrderActionDTO actionDTO) {
ResponseDTO responseDTO = null;
try {
utx.begin();
responseDTO = (ResponseDTO) jmsUtil.read(replyQueue);
if (responseDTO != null) {
//do some action
} else { // timeout
((TemporaryQueue) replyQueue).delete();
jmsUtil.dispose();
}
utx.commit();
return responseDTO;
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
}
}
return responseDTO;
}
}