[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Semantic on Session.stop and MessageHandler
clebert.suconic@jboss.com
do-not-reply at jboss.com
Tue Mar 17 16:31:27 EDT 2009
I am writing this following test on ClientConsumerTest.
If I just call session.stop, the MessageHandler keeps being called until all the messages on the clientBuffer are consumed, but if I call consumer.setHandler(null) I would have the behaviour I expected.
So.. what's the expected semantic from the user's perspective? Shouldn't session.stop prevent any messages being delivered to the handler after stop is called?
| public void testStopConsumer() throws Exception
| {
| ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory"));
|
| final ClientSession session = sf.createSession(false, true, true);
|
| session.createQueue(QUEUE, QUEUE, null, false, false);
|
| ClientProducer producer = session.createProducer(QUEUE);
|
| final int numMessages = 100;
|
| for (int i = 0; i < numMessages; i++)
| {
| ClientMessage message = createMessage(session, "m" + i);
| producer.send(message);
| }
|
| final ClientConsumer consumer = session.createConsumer(QUEUE, null, true);
|
| session.start();
|
| final CountDownLatch latch = new CountDownLatch(10);
|
| // Message should be in consumer
|
| class MyHandler implements MessageHandler
| {
| boolean failed;
| boolean started = true;
|
| public void onMessage(final ClientMessage message)
| {
|
| try
| {
| if (!started)
| {
| failed = true;
| }
|
| latch.countDown();
|
| if (latch.getCount() == 0)
| {
| started = false;
| session.stop();
| consumer.setMessageHandler(null); // the test will fail if we comment out this line
| }
|
| message.acknowledge();
| }
| catch (Exception e)
| {
| }
| }
| }
|
| MyHandler handler = new MyHandler();
|
| consumer.setMessageHandler(handler);
|
| latch.await();
|
| Thread.sleep(100);
|
| assertFalse(handler.failed);
|
| // Make sure no exceptions were thrown from onMessage
| assertNull(consumer.getLastException());
|
| for (int i = 0; i < 90; i++)
| {
| ClientMessage msg = consumer.receive(1000);
| assertNotNull(msg);
| msg.acknowledge();
| }
|
| assertNull(consumer.receiveImmediate());
|
| session.close();
| }
|
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4218814#4218814
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4218814
More information about the jboss-dev-forums
mailing list