繁体   English   中英

JMS Producer中的TimeToLive杀死了我的消息

[英]TimeToLive in JMS Producer kills my Message

如果我在生产者中设置了TimeToLive,则我的订阅者不会收到任何消息。 我使用activeMQ V. 5.13.3作为消息代理。

我的制片人

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);

我的消费者

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));

如果我不使用setTimeToLive(),则消费者收到消息,但使用setTTL()则消息没有到达消费者-不小于或大于10秒钟定义的TTL! 为什么? 错误在哪里?

谢谢

可能是您的客户端和服务器的系统时钟不同步。

这可能是尼古拉斯所说的。 消费者和代理系统时钟不同步。

我使用的是ActiveMQ 5.14.5,并且存在将ActiveMQConnectionFactory的“ consumerExpiryCheckEnabled”属性设置为“ false”来“解决”的相同问题。
这样,使用者仍然可以接收和分发消息,而无需更改消息的“生存时间”或确保使用者和代理系统时钟同步。

请注意,我使用此解决方案是因为:

  1. 我无法同步系统时钟。
  2. 我仅使用“生存时间”来限制队列大小,即,没有收到“已过期”消息的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM