Jms MDB onMessage()在重新传递消息时保持连接

Jms MDB onMessage()在重新传递消息时保持连接,jms,message-driven-bean,openmq,Jms,Message Driven Bean,Openmq,如果无法处理消息,例如由于某些外部端点故障,我需要重新传递消息。因此,我使用以下MDB配置(值得一提的是,我使用的是openMQ(Glassfish 4.1)): 下面是onMessage()方法: 为了重新传递消息,还可以回滚事务,但是openMQ缺少重新传递间隔的属性,因此它不适合我: 总而言之,重新传递工作正常,除了一个时刻:如果消息要重新传递,mdb不会释放连接并将其保持在endpointExceptionRedeliveryInterval*EndpointExceptionRe

如果无法处理消息,例如由于某些外部端点故障,我需要重新传递消息。因此,我使用以下MDB配置(值得一提的是,我使用的是openMQ(Glassfish 4.1)):

下面是onMessage()方法:

为了重新传递消息,还可以回滚事务,但是openMQ缺少重新传递间隔的属性,因此它不适合我:

总而言之,重新传递工作正常,除了一个时刻:如果消息要重新传递,mdb不会释放连接并将其保持在endpointExceptionRedeliveryInterval*EndpointExceptionRedeliveryAttents,在我的例子中为5分钟。因此,因为maxPoolSize的默认值是32,32条“坏”消息足以阻止mdb


有没有办法在重新传递消息时释放连接?

根据JMS规范,这是预期的行为,我不认为在某种消息处理过程中有办法释放连接对象。除“4.3.5关闭连接”外,阅读JMS规范和以下相关内容:

如果连接的一个或多个会话的消息侦听器 在调用连接关闭点处理消息时,所有 连接设施及其会话必须保持可用 直到这些侦听器将控制权返回给JMS提供程序

调用连接关闭时,在收到消息之前不应返回 处理程序已有序关闭。这意味着所有消息 可能正在运行的侦听器已返回,并且 待处理的接收已返回

我不知道你为什么要使用这么高的重试次数,10次尝试太多了,我现在看到的最多是3次,我想你可以尝试调整你的重试次数,或者可能有另一个连接专门用于重新传递

@MessageDriven(mappedName = "MyQueue",  name = "MyQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "10"),
@ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryInterval", propertyValue = "30000")})
  @Override
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void onMessage (Message message)
  {
    try
    {
      //some processing here
    }
    catch (JMSException jmsException)
    {
      logger.log (Level.SEVERE, "Exception processing notification message", jmsException);
    }
    catch (BackingStoreException e)
    {
      // because of throwing RuntimeException, the message is going to be redelivered according to mdb configuration params(interval and attempts count)
      throw new RuntimeException ();
    }
  }