2012-10-02 54 views
1

我們在這個weblogic10.3.4和JMS隊列上建立了,下面是消息監聽器代碼,它使用Spring JMS,MessageProducer設置爲ClientAcknowledgeMode。當發生異常時,消息仍然被移出隊列並回滾,下面的代碼有什麼問題?weblogic JMS隊列消息沒有回滾到異常

public class EmailListener implements MessageListener,ExceptionListener{ 



    private EmailSend emailSend; 



    @SuppressWarnings("unchecked") 
    public void onMessage(Message message){ 
     ObjectMessage om ; 
     try { 
      if(message instanceof ObjectMessage) { 
       om = (ObjectMessage)message; 
       emailSend.sendEmail((Map<String, String>)om.getObject()); 
       //throw new JMSException("Test"); 
       om.acknowledge(); 

      } 
     } 
     catch(MailException me) { 
      logger.error("Mail server exception in sending email",me); 
      throw new RuntimeException(me); 
     }catch(JMSException jmse) { 
      logger.error("Error in sending email",jmse); 
      throw new RuntimeException(jmse); 

     } 

    } 

    public void setEmailSend(EmailSend emailSend){ 
     this.emailSend = emailSend; 
    } 

    public void onException(JMSException jmse){ 
     logger.error("Exception in sending email",jmse); 

    } 
    public void acknowledge(
    ) throws JMSException{ 

    } 
} 

下面是Spring配置

<!--Spring JMS Message Listener Container --> 
    <bean id="jmsContainer" 
     class="org.springframework.jms.listener.DefaultMessageListenerContainer" 
     p:autoStartup="true" p:destination-ref="queue" 
     p:destinationResolver-ref="jmsDestinationResolver" 
     p:connectionFactory-ref="authenticationConnectionFactory" 
     p:exceptionListener-ref="emailListener" 
     p:messageListener-ref="emailListener" /> 

回答

0

您需要澄清一點。標題表示您的消息不會回滾到隊列,而帖子中的文字則說明消息已回滾。

從來沒有少,幾個三分球讓你回滾行爲正確:

不要依賴確認。實際上,它們並不打算成爲應用程序邏輯級別的重新傳遞。你可以閱讀關於它的一些細節here。所以,ack不會讓你在例外情況下重新交付,但交易將會。

您可以在DMLC上設置p:sessionTransacted =「true」。這可能是你想要的 - 如果你得到一個異常,消息將被回滾到隊列中。

如果您開始在此包含數據庫連接,則應該從WebLogic JNDI存儲庫中取出Jta事務管理器,並將其作爲p:transactionManager在DMLC上進行注入,因爲會話事務僅支持一個資源事務。