MessageListener停止监听HornetQ队列

时间:2018-12-04 10:25:00

标签: netty jboss7.x hornetq jboss-mdb

以下问题正在损害我的生产系统。因此,我将多个MDB打包为EAR,WAR应用程序,并部署在JBOSS中。当我的网站中有大量流量时,这些MDB停止侦听正在HornetQ中写入队列的消息,因此我被迫重新启动系统。上次发生这种情况的时候,我编写了一个独立的消息侦听器,并且能够侦听来自同一总部服务器的消息。这指出了问题出在我的应用程序服务器/应用程序级别。我附上以下内容:

  1. 典型的MDB

    @MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), 
        @ActivationConfigProperty(propertyName = "destination", propertyValue = Queues.CHAT_HANDLER),})
    @ResourceAdapter("hornetq-ra.rar")
    public class ChatHandlerQueueListener implements MessageListener {
    
     public static final Logger logger = LoggerFactory.getLogger(ChatHandlerQueueListener.class);
    
     @Inject
     IChatManager chatManager;
    
     public void onMessage(Message message) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        ComponentMessage routingEngineResponse = null;
        try {
           routingEngineResponse = (ComponentMessage) objectMessage.getObject();
           boolean messageRedelivered = message.getJMSRedelivered();
           if (logger.isTraceEnabled())
              logger.trace("ChatHandlerQueueListener.callingChatManager Incoming response is {}", JsonUtils.toJson(routingEngineResponse));
           if (routingEngineResponse == null)
              return;
           if (messageRedelivered) {
              // Sending the message acknowledgement manually
              message.acknowledge();
           }
    
        } catch (JMSException e) {
           logger.error("ChatHandlerQueueListener.onMessage Type: null", e);
        }
        if (routingEngineResponse.getType().equals(MessageType.ChatAction) || routingEngineResponse.getType().equals(MessageType.ChatTransfer)) {
           try {
              logger.debug("ChatHandlerQueueListener.callingChatManager {}", JsonUtils.toJson(routingEngineResponse));
              chatManager.processRoutingEngineResponseMessage(routingEngineResponse);
           } catch (UnknownReActionTypeException e) {
              logger.error("ChatHandlerQueueListener.onMessage Type: UnknownReActionTypeException {}", e);
           }
        } else if (routingEngineResponse.getType().equals(MessageType.InboundSms)) {
           logger.debug("Calling request for agent {}", JsonUtils.toJson(routingEngineResponse));
           try {
              chatManager.processChatMessage(routingEngineResponse);
           } catch (ChatServiceUnavailableException | JMSException | ApplicationException e) {
              logger.error("ChatHandlerQueueListener.onMessage Type: Exception {}", e);
           }
        } else if (routingEngineResponse.getType().equals(MessageType.ChatMessage)) {
           try {
              chatManager.processChatMessage(routingEngineResponse);
           } catch (ChatServiceUnavailableException | JMSException | ApplicationException e) {
              logger.error("ChatHandlerQueueListener.onMessage Type: Exception {}", e);
           }
        } else if (routingEngineResponse.getType().equals(MessageType.TropoSmsDelivery)) {
           logger.debug("Calling smsDelvieryHandler {}", JsonUtils.toJson(routingEngineResponse));
           try {
              chatManager.processSmsDeliveryMessage(routingEngineResponse);
           } catch (Exception e) {
              logger.error("ChatHandlerQueueListener.onMessage Type: Exception {}", e);
           }
        } else {
           try {
              logger.trace("Unexpected message seletor found: {}", message.getStringProperty("MESSAGE_TYPE"));
           } catch (JMSException e) {
              logger.error("ChatHandlerQueueListener.onMessage Type: Exception {}", e);
           }
        }
     }
    

    }

  2. JBOSS配置文件

    <hornetq-server>
       <persistence-enabled>true</persistence-enabled>
       <connectors>
          <connector name="netty">
             <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
             <param key="host" value="${jboss.bind.remote.hq.address}"/>
             <param key="port" value="${jboss.bind.remote.hq.port}"/>
          </connector>
       </connectors>
       <jms-connection-factories>
          <connection-factory name="RemoteConnectionFactory">
             <connectors>
                <connector-ref connector-name="netty"/>
             </connectors>
             <entries>
                <entry name="RemoteConnectionFactory"/>
             </entries>
          </connection-factory>
          <pooled-connection-factory name="hornetq-ra">
             <transaction mode="xa"/>
             <connectors>
                <connector-ref connector-name="netty"/>
             </connectors>
             <entries>
                <entry name="java:/JmsXA"/>
             </entries>
          </pooled-connection-factory>
       </jms-connection-factories>
    </hornetq-server>
    

1 个答案:

答案 0 :(得分:0)

当MDB停止接收消息时,您需要获取一系列线程转储,以查看MDB线程在做什么(如果有的话)。通常,此类问题是由特定于应用程序的问题引起的,可以通过线程转储轻松识别。