2013-08-21 55 views
0

我得到這個消息不承認錯誤:JMS消息不承認錯誤

javax.jms.IllegalStateException: Message not delivered 
at com.tibco.tibjms.TibjmsxSessionImp._confirmNonTransacted(TibjmsxSessionImp.java:3295) 
at com.tibco.tibjms.TibjmsxSessionImp._confirm(TibjmsxSessionImp.java:3644) 
at com.tibco.tibjms.TibjmsxSessionImp._confirmNonAuto(TibjmsxSessionImp.java:4980) 
at com.tibco.tibjms.TibjmsMessage.acknowledge(TibjmsMessage.java:609) 

這裏是我的代碼:

public processMessage(Message pMessage){ 
    try{ 
     performOperation(); 
    } 
    catch(Exception e){ 
    }finally{ 
     if (pMessage != null) { 
      try { 
       pMessage.acknowledge(); 
      } catch (Exception e) { 
       try { 
        if (pMessage.getJMSRedelivered()) { 
         log.info("Message has been redelivered"); 
        } else 
         log.error(("Message has not been delivered"),e); 
       } catch (JMSException e1) { 
        log.error(e1); 
       } 
      } 
     } 
     return null; 
    } 

public boolean performOperation(somedata){ 
    try{ 
    insert into database 
    } 
    catch(DataIntegrityViolationException e){ 
     do something 
     if (pMessage != null){ 
     pMessage.acknowledge(); 
     } 
    } 
} 

    } 

回答

0

你是如何創建的JMS會話?你只能做客戶端在非事務處理模式確認,所以一定要確保會話建立這樣的:

connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); 

此外,你在做finallymessage.acknowledge(),這意味着如果performOperation()失敗了,你承認消息,意味着消息將不會被重新發送以進行另一次嘗試。考慮做這樣的事情時的performOperation()消息是基於經紀人的配置重新發送失敗這其中:

public processMessage(Message pMessage){ 
    try{ 
     performOperation(); 
     pMessage.acknowledge(); 
    } 
    catch(Exception e){ 
    } 
+0

我不知道是如何被創建的JMS會話,我已經更新了代碼。 APP在prop中配置了生產者和消費者。 – user1910892

+0

這是行不通的,除非你將它作爲參數傳遞,否則'pMessage'不在'processMessage()'的作用域中。您應該在processMessage()中確認並保留所有與消息相關的操作。 – raffian

+0

我傳遞pMessage作爲參數。看得更清楚我在performOperation方法中有不同的條件,並且我在每個條件之後都承認,但是對於每條成功的消息,我正在使用finally確認。 – user1910892