[jboss-user] [Messaging, JMS & JBossMQ] - Re: JMS Framework Stops on changing System Time

njain15 do-not-reply at jboss.com
Mon May 21 08:17:50 EDT 2007


Not sure if someone still looking for the answer. We had similar issue and looking at the JBoss code, figured out following -

Whenever a JMS connection is created in JBoss, JBoss schedules a thread that checks for the validity of the connection. The validity criteria is such that JBoss expects another message from the connection's client with in 2 min (by default, it might be configurable) since last message is received. If no message is received from client then connection is considered stale and closed. 

The exception in your case is because of this behavior.

Since a JMS client application may not send a message every two minutes, the JMS implementation sends a PingMessage to the connection every 60 sec to keep it alive.

To schedule the PING for every 60 sec, JBoss uses the ClockDeamon class from 'EDU', that provides a feature to schedule a task periodically. The application works as expected if you increase the system time. If system time is decreased, it fails to send to PING message every 60 sec and hence connection times out after 2 min.

Look at the implementation of 'nextTask' method in 'ClockDeamon' class for details. 

One of the possible approach to fix the issue is to register a javax.jms.ExceptionListener with the JMS connection. This listener is notified whenever JMS system encounters any error with the connection. During call back, you should recreate the connection and all the associated JMS objects.

Here is snippet of a TextMDB (will not compile as it is, removed unnecessary code to reduce the text) that uses the above mentioned approach

public class TextMDB implements MessageDrivenBean, MessageListener, ExceptionListener
{

  private MessageDrivenContext ctx = null;
  private QueueConnection conn;
  private QueueSession session;

  public void ejbCreate() {
      setupPTP();
  }

  public void onMessage(Message msg) {
      TextMessage tm = (TextMessage) msg;
      String text = tm.getText() + "processed by: " + hashCode();
      Queue dest = (Queue) msg.getJMSReplyTo();
      sendReply(text, dest);
  }

  private void setupPTP() throws JMSException, NamingException {
    InitialContext iniCtx = new InitialContext();
    Object tmp = iniCtx.lookup("java:comp/env/jms/QCF");
    QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
    conn = qcf.createQueueConnection();
    conn.setExceptionListener(this);
    session = conn.createQueueSession(false,
                                      QueueSession.AUTO_ACKNOWLEDGE);
    conn.start();
  }

  private void sendReply(String text, Queue dest) throws JMSException {
    QueueSender sender = session.createSender(dest);
    TextMessage tm = session.createTextMessage(text);
    sender.send(tm);
    sender.close();
  }

  public void onException(JMSException jMSException) {
      setupPTP();
  }
  
}

Hope this helps

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4047213#4047213

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4047213



More information about the jboss-user mailing list