0
我試圖寫一個JUnit測試表明,一個JMS用戶的的start()函數揭開序幕消息監聽器主題(的消息以及沒有被的start()調用之前消耗)。JMS MockTopic消息沒有被消息監聽器拾取嗎?
我遇到了在的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**)
雖然這表明偵聽器未啓動()之前運行時,拉開消息偵聽器應目前導致對主題的所有消息以進行處理。
我已經嘗試通過增加以確保持久性是不是原因:
objectMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
但這並沒有幫助。
實際運行的程序,似乎表明目前存在的主題消息上的start()進行處理。有誰知道爲什麼MockTopic目前的消息可能沒有得到處理開始()?是否是MockTopic的限制?
這是一個很好的觀點。我不確定這是否是這個特定測試的問題,但值得研究。實際的訂閱設置爲持久,但我不確定是否能夠正確進行測試。 –