2012-07-27 50 views
0

標題可能會令人困惑,但這是我想完成。我想從1 ejb發送一個jms消息到另一個,第二個ejb有一個消息監聽器,現在這個工作正常。但我想讓第一個ejb創建一個臨時目標隊列,第二個ejb會響應 - 這也正常工作。JMS失效後,它已經收到不起作用

我的問題是在第二個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. 

因此,它已收到,但沒有答覆呢。然後在時間,其中將寫入臨時隊列應該已過期,但由於某種原因,我仍然能夠寫入隊列和我有FF在我的IMQ日誌:

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

它現在可以工作了,我的解決方案是在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; 
    } 
}