JMS消息未确认错误

时间:2013-08-21 17:35:37

标签: java 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();
       }
   }
}

    }

1 个答案:

答案 0 :(得分:0)

您是如何创建JMS会话的?您只能在非事务处理模式下进行客户端确认,因此请确保会话设置如下:

connection.createSession( false, Session.CLIENT_ACKNOWLEDGE);

此外,您正在message.acknowledge()中执行finally,这意味着如果performOperation()失败,您仍然会确认该消息,这意味着该消息不会再次传递给另一次尝试。考虑做这样的事情,在performOperation()失败时根据代理配置重新传递消息:

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