activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodrigo S de Castro <ro...@terra.com.br>
Subject Re: Redelivery problem with MessageListener and Session rollback
Date Mon, 24 Apr 2006 01:38:46 GMT
Hi Hiram,

Thanks for your answer and sorry for taking so long to answer. Attached 
you will find two tests:

1 - Class MessageListenerRedeliveryTestActiveMQ3: tests redelivery in 
ActiveMQ 3 when message is rolled back in a MessageListener. It shows 
that redelivery policy (including initial timeout as well as back off 
mode) are not followed. The only setting that works in the policy is the 
maximum number of tries. Tested with 3.2.2

2 - Class MessageListenerRedeliveryTestActiveMQ4: tests redelivery in 
ActiveMQ 4 when message is rolled back in a MessageListener (same as 
above). Redelivery policy does not work at all in this version when the 
message is rolled back in MessageListener. It also tests the number of 
retries as well as if the initial timeout and back off mode. Tested with 
ActiveMQ 4 RC2.

I would like to contribute these classes to Apache ActiveMQ. I will be 
happy to hear comments and make any necessary adjustments in this code.

Cheers,

Rodrigo


Hiram Chirino wrote:
> Hi Rodrigo,
>
> Is that junit test a patch you want to contibute to Apache?  If so,
> I'll add it to our test suite asap.
>
> Regards,
> Hiram
>
> On 4/15/06, Rodrigo S de Castro <rodsc@terra.com.br> wrote:
>   
>> Hi,
>>
>> 1) I have a MessageListener implementation that rolls back the session if
>> something goes wrong. I expected the message to be redelivered to this
>> listener, but that does not happen. It is never redelivered.
>>
>> This code does NOT work:
>>
>>     private class MessageListenerTest implements MessageListener {
>>         private Session session;
>>         public int counter = 0;
>>
>>         public MessageListenerTest(ActiveMQMessageConsumer session) {
>>                 this.session = session;
>>         }
>>
>>                 public void onMessage(Message message) {
>>                         try {
>>                                 System.out.println("Message: " + message);
>>                                 counter++;
>>                                 if (counter <= 2) {
>>                                         System.out.println("ROLLBACK");
>>                                         session.rollback();
>>                                 } else {
>>                                         System.out.println("COMMIT");
>>                                         message.acknowledge();
>>                                         session.commit();
>>                                 }
>>                         } catch(JMSException e) {
>>                                 System.err.println("Error when rolling back transaction");
>>                         }
>>                 }
>>     }
>>
>>
>> 2) The only I managed to make it redeliver is to pass a reference to
>> MessageConsumer to the MessageListener implementation, cast it to
>> ActiveMQMessageConsumer and call its rollback method.
>>
>> The code below DOES work:
>>
>>     private class MessageListenerTest implements MessageListener {
>>         private ActiveMQMessageConsumer consumer;
>>         public int counter = 0;
>>
>>         public MessageListenerTest(ActiveMQMessageConsumer consumer) {
>>                 this.consumer = consumer;
>>         }
>>
>>                 public void onMessage(Message message) {
>>                         try {
>>                                 System.out.println("Message: " + message);
>>                                 counter++;
>>                                 if (counter <= 2) {
>>                                         System.out.println("ROLLBACK");
>>                                         session.rollback();
>>                                 } else {
>>                                         System.out.println("COMMIT");
>>                                         message.acknowledge();
>>                                         session.commit();
>>                                 }
>>                         } catch(JMSException e) {
>>                                 System.err.println("Error when rolling back transaction");
>>                         }
>>                 }
>>     }
>>
>> It this right? I think that session.rollback() should work as well.
>>
>> Below a JUnit code that shows this problem:
>>     
[...]



Mime
View raw message