gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:34:39 28 4
gpt4 key购买 nike

如果我在生产者中设置了 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!为什么?哪里错了?

谢谢

最佳答案

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

关于java - JMS Producer 中的 TimeToLive 杀死了我的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37592932/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com