JBOSS EAP 6.4.5 Behavior of Message Consumer recieve message with timeout
daedlus Oct 8, 2016 2:02 PMHi ,
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:
@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class ProcessQueue {
/**
*
* @param timerContext
*/
@Asynchronous
public void process(Object info) {
System.out.println("*********Started Processing " + info + "****************");
QueueConsumer consumer = null;
try {
consumer = new QueueConsumer();
consumer.initialize();
Object poppedRequest = consumer.getQueuedRequest(5000);
System.out.println("message==>" + poppedRequest);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (consumer != null) {
consumer.destroy();
}
}
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);
connection.start();
} 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 {
session.close();
} catch (final JMSException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (final JMSException e) {
e.printStackTrace();
}
}
}
}
Client JMS Connection Factory has below settings to connect to remote-jms:
<connection-factory name="RemoteConnectionFactory"> <connectors> <connector-ref connector-name="remote-jms1"/> </connectors> <entries> <entry name="java:/ConnectionFactory"/> </entries> <retry-interval>500</retry-interval> <retry-interval-multiplier>5</retry-interval-multiplier> <max-retry-interval>10000</max-retry-interval> <reconnect-attempts>32767</reconnect-attempts> </connection-factory>
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/127.0.0.1:5445
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