I use ActiveMQ as a message delivery broker. These posts are for writing in dabatas. Sometimes the database is unavailable or inaccessible. In this case, I want to cancel my message in order to repeat this message later, and I want to continue reading other messages.
This code works fine, except for one point: the rollback message blocks 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(); ((ActiveMQConnection)connection).setUseAsyncSend(true); ((ActiveMQConnection)connection).setDispatchAsync(true); ((ActiveMQConnection)connection).setRedeliveryPolicy(redeliveryPolicy); ((ActiveMQConnection)connection).setStatsEnabled(true); connection.setClientID("myClientID"); return connection; }
I create a session as follows:
session = connection.createSession(true, Session.SESSION_TRANSACTED);
Rollback can be easily asked:
session.rollback();
Suppose 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 set my Consumer to a later delay in my rollback messages?
java jms activemq
Jean-philippe caruana
source share