Version 4

    JBossMQ TimeToLive is not working properly

     

    When I configure TimeToLive (TTL) for my messages it is not working properly,

    either the messages are expiring too early or they are not expiring at all.

     

    Your clocks are out-of-sync

     

    In JMS there is no real TTL associated with messages. What there is an expiry time.

    javax.jms.Message.getJMSExpiration()

    . This is the time in UTC (Universal time also known as GMT or CUT).

     

    This is the time that should be returned when you invoke

    System.currentTimeMillis()

     

    Fix your clock

     

    Fix your clocks and timezone on your server and clients if you want this to work properly.

     

    Workaound

     

    Write a JBossMQ interceptor that recalcuates the expiry time on the server using its clock.

     

    That is change the example interceptor to do a

    recalculateExpiration()

     

    protected void recalculateExpiration(SpyMessage message) throws JMSException
    {
       long expiration = message.getJMSExpiration();
       if (expiration != 0)
       {
          long sent = message.getJMSTimeStamp();
          
          // Recalculate
          long newExpiration = System.currentTimeMillis() + expiration - sent;
    
          // Update the message
          message.setJMSExpiration(newExpiration);
       }
    }