0

if i set the TimeToLive in my Producer, my Subscriber doesn't receive any message. I use an activeMQ V. 5.13.3 as message broker.

My Producer

javax.naming.Context ctx = new InitialContext();
// lookup the connection factory
factory = (javax.jms.TopicConnectionFactory)ctx.lookup("ConnectionFactory");
// create a new TopicConnection for pub/sub messaging
connection = factory.createConnection("user", "pwd");
// lookup an existing topic
destination = (javax.jms.Topic)ctx.lookup("MyTopic");
// create a new TopicSession for the client
session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE);

connection.start();

producer = session.createProducer(destination);
producer.setTimeToLive(10000);

TextMessage message = session.createTextMessage();
message.setText("The Message");
producer.send(message);

My Consumer

javax.naming.Context ctx = new InitialContext();
// lookup the connection factory
factory = (javax.jms.TopicConnectionFactory)ctx.lookup("ConnectionFactory");
// create a new TopicConnection for pub/sub messaging
connection = factory.createConnection("user", "pwd");
connection.setClientID("ClientID-"+id);
connection.start();
// lookup an existing topic
destination = (javax.jms.Topic)ctx.lookup("MyTopic");
// create a new TopicSession for the client
session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE);

consumer = session.createDurableSubscriber(destination, id);

consumer.setMessageListener(new MessageListenerConsumer("ClientID-"+id));

If i doesn't use setTimeToLive() the consumer receive the message but with setTTL() no message arrive's the consumer - not less or more as the defined 10 seconds TTL! Why? Where is the mistake?

Thx

Tim
  • 643
  • 3
  • 12
  • 23
  • How is that a problem and what is the question, TTL does exactly this – Tim Bish Jun 02 '16 at 13:17
  • Sorry, first i start my consumerListener und then i start my producer. Without TTL i get the message less than 1 second. In my producer is set TTL to 10 seconds - so i would expect the consumer receive the message with and without TTL. I expected, if i start my consumer more than 10 seconds after sending the message, then i doesn't get the message – Tim Jun 02 '16 at 13:31

2 Answers2

2

Could be that your client's and server's system clocks are out of sync.

Nicholas
  • 15,916
  • 4
  • 42
  • 66
0

It's probably what Nicholas said. Consumer and broker system clocks are out of sync.

I'm using ActiveMQ 5.14.5 and had the same problem which I "solved" by setting the ActiveMQConnectionFactory's "consumerExpiryCheckEnabled" property to 'false'.
This way the consumer still receives and dispatches the message without the need to change messages 'time-to-live' or to guarantee that consumer and broker system clocks are synced.

Note that I'm using this solution because:

  1. I'm not able to synchronize the system clocks.
  2. I'm using the 'time-to-live' only to limit the queue size, ie, there's no problem of receiving an "already expired" message.
João Ferreira
  • 191
  • 1
  • 10