[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: JMSMessage.ack call is equivalent to JMSSession.commit()

clebert.suconic@jboss.com do-not-reply at jboss.com
Wed Mar 25 19:16:32 EDT 2009


It should be a simple fix, but to fix that I would need access to JBossSession from JBossMessage, or the ACKMode as a property on JBossMessage.


This is the complete test:


  | class AcknowledgementTest
  | ....
  | 
  | 
  |    public void testTransactionalAcknowledgementClientCallingACK() throws Exception
  |    {
  |       Connection conn = null;
  | 
  |       try
  |       {
  |          conn = cf.createConnection();
  | 
  |          Session producerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
  |          MessageProducer producer = producerSess.createProducer(queue1);
  | 
  |          Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
  |          MessageConsumer consumer = consumerSess.createConsumer(queue1);
  |          conn.start();
  | 
  |          final int NUM_MESSAGES = 20;
  | 
  |          // Send some messages
  |          for (int i = 0; i < NUM_MESSAGES; i++)
  |          {
  |             Message m = producerSess.createMessage();
  |             //m.acknowledge(); // This is invalid but this call should be ignored accordingly to the javadoc
  |             producer.send(m);
  |          }
  |          
  |          assertRemainingMessages(0);
  | 
  |          producerSess.rollback();
  | 
  |          // Send some messages
  |          for (int i = 0; i < NUM_MESSAGES; i++)
  |          {
  |             Message m = producerSess.createMessage();
  |             producer.send(m);
  |          }
  |          assertRemainingMessages(0);
  | 
  |          producerSess.commit();
  | 
  |          assertRemainingMessages(NUM_MESSAGES);
  | 
  | 
  |          int count = 0;
  |          while (true)
  |          {
  |             Message m = consumer.receive(200);
  |             if (m == null)
  |             {
  |                break;
  |             }
  |             m.acknowledge();
  |             count++;
  |          }
  |                   
  |          assertRemainingMessages(NUM_MESSAGES);
  | 
  |          assertEquals(count, NUM_MESSAGES);
  | 
  |          consumerSess.rollback();
  | 
  |          assertRemainingMessages(NUM_MESSAGES);
  | 
  |          int i = 0;
  |          for (; i < NUM_MESSAGES; i++)
  |          {
  |             consumer.receive();
  |          }
  | 
  |          assertRemainingMessages(NUM_MESSAGES);
  | 
  |          // if I don't receive enough messages, the test will timeout
  | 
  |          consumerSess.commit();
  | 
  |          assertRemainingMessages(0);
  | 
  |          checkEmpty(queue1);
  |       }
  |       finally
  |       {
  |          if (conn != null)
  |          {
  |             conn.close();
  |          }
  |       }
  |    }
  | 
  | 
  | 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4221139#4221139

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4221139



More information about the jboss-dev-forums mailing list