I am trying to write a jUnit test to show that a JMS Subscriber's start() function kicks off the message listener for a Topic (and that messages were not being consumed before start() was called).
I am running into an issue where messages placed on the Topic before the start() function is called are not processed once start() is called. Messages placed on the Topic after start() is called are processed immediately.
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**)
// p开发者_高级运维ublish a message for the listener to pick up
topicWriter.addMessage(objectMessage);
//...assert that the message gets processed... (**SUCCEEDS**)
While this shows that the listener is not running before start(), kicking off the message listener should cause all messages currently on the Topic to be processed.
I've attempted to make sure that persistency wasn't the cause by adding:
objectMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
but this did not help.
Actually running the program seems to indicate that messages currently residing on the Topic are processed on start(). Does anyone know why the messages currently on the MockTopic might not be getting processed at start()? Is it a limitation of MockTopic?
I'm not totally clear if this is a MockTopic issue, but with respect to standard JMS, you would not expect a started listener to receive messages published before it started unless it was a durable subscription. The persistence is neither here nor there.
精彩评论