我试图使用这两种方法中的任何一种,以至于通过该生产者发送的消息将会过期。例如,我已经设置了5秒(5 000毫秒)的时间,但即使在5秒后,我订阅后我仍然收到消费者的消息。我不知道为什么......为什么不JMS MessageProducer方法setTimeToLive或send()工作?
1
A
回答
1
规格如下说,
当达到一个消息的到期时间,供应商应该抛弃 它。 JMS API没有定义任何形式的消息通知到期。客户不应收到已过期的消息;但是,JMS API并不能保证不会发生这种情况。
所以它的完全实现具体。您的发布者/订阅者应按照JMS规范放弃过期邮件的方式来实现,如果不是,即使您没有在到期时间之后仍然收到这些邮件。
1
也许你做错了什么。试试我的测试
String url = "tcp://localhost:61616";
BrokerService broker = new BrokerService();
broker.addConnector(url);
broker.start();
ConnectionFactory cf = new ActiveMQConnectionFactory(url);
Connection conn = cf.createConnection();
Session s = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue q = new ActiveMQQueue("test");
MessageProducer p = s.createProducer(q);
p.send(s.createTextMessage("!!!!"), DeliveryMode.NON_PERSISTENT, 0, 1000); // ttl = 1s
Thread.sleep(2000);
MessageConsumer c = s.createConsumer(q);
System.out.println("Received: " + c.receiveNoWait());
System.exit(1);
它使用ActiveMQ的,全5.6.0.jar,TTL = 1秒,你会看到,如果你的睡眠时间大于1s,你送了它从队列中消失的消息后。
相关问题
- 1. JMS setTimeToLive
- 2. 为什么Math.random方法不工作?
- 3. 为什么nextInt()方法不工作?
- 4. Socket.IO send()不工作
- 5. 为什么getElementsByClassName方法不工作,而工作的getElementById?
- 6. 为什么JMS监听器工作不落实一个MessageListener
- 7. 为什么document.location或window.location不能工作?
- 8. 为什么不是pip或easy_install工作?
- 9. 为什么script send/n?
- 10. 简单的JMS示例不检索JMS消息。为什么?
- 11. 为什么协方差不与泛型方法工作
- 12. 为什么不CGPathIsRect工作?为什么CGPathContainsPoint不工作?
- 13. void方法不同,或者为什么我不能调用void方法,当int方法工作正常?
- 14. 为什么仅在使用`send`时才查找Kernel方法?
- 15. 不明白为什么我的方法不工作?
- 16. 为什么方法不起作用?
- 17. 为什么integerValidation方法不起作用?
- 18. 为什么log4javascript.trace方法不起作用?
- 19. 为什么.downto方法不起作用?
- 20. 为什么focus()方法不起作用?
- 21. 为什么datamapper方法不起作用?
- 22. 为什么didrecivedlocalnotification方法不起作用?
- 23. 为什么POST方法不起作用?
- 24. 为什么此方法不起作用?
- 25. 为什么class.click方法不起作用?
- 26. 这里有什么问题?为什么PHP或它不工作?
- 27. 为什么不std :: noskipws工作,或者它应该做什么?
- 28. 为什么不工作
- 29. 为什么WAMP不工作?
- 30. 为什么history.pushState不工作?