【发布时间】:2011-10-09 18:38:32
【问题描述】:
我正在尝试编写一个 jUnit 测试来显示 JMS 订阅者的 start() 函数会启动 Topic 的消息侦听器(并且在调用 start() 之前没有使用消息)。
我遇到了一个问题,即在调用 start() 函数之前放置在主题上的消息在调用 start() 后不会被处理。在调用 start() 之后放置在主题上的消息会立即被处理。
MockTopic topicWriter = getMockTopic(TOPIC);
// publish a message for the listener to pick up
MockObjectMessage objectMessage = new MockObjectMessage(message);
objectMessage.setBooleanProperty("Broadcast", true);
topicWriter.addMessage(objectMessage);
// the message doesn't get consumed because the subscriber has not been started
//...assert that the message is not processed... (**SUCCEEDS**)
// start the subscriber/listener
subscriber.start();
//...assert that the messages sitting on the topic get processed... (**FAILS**)
// publish a message for the listener to pick up
topicWriter.addMessage(objectMessage);
//...assert that the message gets processed... (**SUCCEEDS**)
虽然这表明侦听器在 start() 之前没有运行,但启动消息侦听器应该会导致处理当前主题上的所有消息。
我试图通过添加以下内容来确保持久性不是原因:
objectMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
但这没有帮助。
实际运行程序似乎表明当前驻留在 Topic 上的消息在 start() 上处理。有谁知道为什么当前在 MockTopic 上的消息可能无法在 start() 处得到处理?是 MockTopic 的限制吗?
【问题讨论】:
标签: java jms mockrunner