activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Philippe Caruana <>
Subject dead letter queue keeps my messages order
Date Wed, 28 Jul 2010 12:21:58 GMT

I use ActiveMQ as a broker to deliver messages. Theses messages are 
intented to be written in a dabatase. Sometimes, the database is 
unreachable or down. In that case, I want to rollback my message to 
retry later this message and I want to continue reading other messages.

This code works fine, except one point : the rollbacked message is 
blocking me from reading the others :

	private Connection getConnection() throws JMSException {
		RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
		redeliveryPolicy.setMaximumRedeliveries(3); // will retry 3 times to 
dequeue rollbacked messages
		redeliveryPolicy.setInitialRedeliveryDelay(5 *1000);  // will wait 5s 
to read that message

		ActiveMQConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory(user, password, url);
		Connection connection = connectionFactory.createConnection();
		return connection;

I create my session this way :

     session = connection.createSession(true, Session.SESSION_TRANSACTED);

Rollback is easy to ask :


Let's imagine I have 3 messages in my queue :

     1: ok
     2: KO (will need to be treated again : the message I want to rollback)
     3: ok
     4: ok

My consumer will do (linear sequence) :

     commit 1
     rollback 2
     wait 5s
     rollback 2
     wait 5s
     rollback 2
     put 2 in dead letter queue (ActiveMQ.DLQ)
     commit 3
     commit 4

But I want :

     commit 1
     rollback 2
     commit 3
     commit 4
     wait 5s
     rollback 2
     wait 5s
     rollback 2
     wait 5s
     put 2 in dead letter queue (ActiveMQ.DLQ)

So, how can I configure my Consumer to delay my rollbacked messages later ?
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'attention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration. Multimedia Business Services decline
toute responsabilite au titre de ce message s'il a ete altere, deforme
ou falsifie.
Si vous n'etes pas destinataire de ce message, merci de le detruire
immediatement et d'avertir l'expediteur.
This message and any attachments (the "message") are confidential and
intended solely for the addressees. Any unauthorised use or
dissemination is prohibited.
Messages are susceptible to alteration. Multimedia Business Services shall not be liable for
message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it
immediately and inform the sender..

View raw message