0 Replies Latest reply on Oct 8, 2016 2:02 PM by inv3r53 d

    JBOSS EAP 6.4.5 Behavior of Message Consumer recieve message with timeout

    inv3r53 d Novice

      Hi ,

      I have the following use case:


      JBOSS-1 [has jms client] ---------------------->JBOSS-2[JMS broker hornetQ]



      Client in JBOSS-1 tries to poll a queue and read a message:


      public class ProcessQueue {
           * @param timerContext
          public void process(Object info) {
              System.out.println("*********Started Processing " + info + "****************");
              QueueConsumer consumer = null;
              try {
                  consumer = new QueueConsumer();
                  Object poppedRequest = consumer.getQueuedRequest(5000);
                  System.out.println("message==>" + poppedRequest);
              } catch (Exception e) {
              } finally {
                  if (consumer != null) {
              System.out.println("*****************completed processing " + info + "***********************");


      public class QueueConsumer {
          private static final String CONNECTION_FACTORY = "java:/ConnectionFactory";
          private Connection connection = null;
          private Session session = null;
          private MessageConsumer messageConsumer = null;
          public void initialize() {
              try {
                  final InitialContext context = new InitialContext();
                  final ConnectionFactory connFactory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY);
                  connection = connFactory.createConnection();
                  session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                  final String channelJNDIName = "java:/queue/TestQueue";
                  final Queue queue = (Queue) context.lookup(channelJNDIName);
                  messageConsumer = session.createConsumer(queue);
              } catch (Exception e) {
                  throw new RuntimeException(e);
          public Object getQueuedRequest(final long consumerTimeout) {
              try {
                  ObjectMessage poppedRequest = null;
                  if (messageConsumer != null) {
                      poppedRequest = (ObjectMessage) messageConsumer.receive(consumerTimeout);
                  if (poppedRequest == null) {
                      return null;
                  return poppedRequest.getObject();
              } catch (final JMSException e) {
                  throw new RuntimeException(e);
          public void destroy() {
              if (session != null) {
                  try {
                  } catch (final JMSException e) {
              if (connection != null) {
                  try {
                  } catch (final JMSException e) {


      Client JMS Connection Factory has below settings to connect to remote-jms:


      <connection-factory name="RemoteConnectionFactory">
                                  <connector-ref connector-name="remote-jms1"/>
                                  <entry name="java:/ConnectionFactory"/>


      The client runs periodically a read messages of the queue using above class ProcessQueue.

      If the JBOSS-2 restarts it is seen that threads keep waiting at consumer.receive(5000) due to retry count of 32767 ..(upon reducing 32767 to 1 it works)

      I see in the logs that reconnect to remote-jms1 is successful but messageconsumer.receive(5000) does not return with exception during JBOSS2 restart


      22:54:19,830 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Trying reconnection attempt 3/32767

      22:54:19,830 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Trying to connect with connector = org.hornetq.core.remoting.impl.netty.NettyConnectorFactory@794b25c1, parameters = {use-nio=false, port=5445, host=localhost} connector = NettyConnector [host=localhost, port=5445, httpEnabled=false, useServlet=false, servletPath=/messaging/HornetQServlet, sslEnabled=false, useNio=false]

      22:54:19,830 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Started Netty Connector version 3.6.10.Final-266dbdf

      22:54:19,830 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Trying to connect at the main server using connector :TransportConfiguration(name=00347dc9-8d7c-11e6-9fc7-853b2a584eed, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?use-nio=false&port=5445&host=localhost

      22:54:19,830 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Remote destination: localhost/

      22:54:19,834 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) Reconnection successfull

      22:54:19,862 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) HQ214027: Couldnt reattach session {0}, performing as a failover operation now and recreating objects

      22:54:19,863 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) ClientSession couldn't be reattached, creating a new session

      22:54:19,878 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) HQ214027: Couldnt reattach session {0}, performing as a failover operation now and recreating objects

      22:54:19,878 DEBUG [org.hornetq.core.client] (Thread-9 (HornetQ-client-global-threads-1683222502)) ClientSession couldn't be reattached, creating a new session



      Would someone please clarify why this behavior is exhibited by the message consumer?


      Thank you