I am trying to move the message from a queue1(Dead Letter queue) to queue2 in active MQ at periodic interval of 5 minutes using Camel router. I am using below code to achieve this :-
public class MessageRouteBuilder extends RouteBuilder {
private static final Logger LOG =
LoggerFactory.getLogger(MessageRouteBuilder.class);
/*
* (non-Javadoc)
*
* @see org.apache.camel.builder.RouteBuilder#configure()
*/
@Override
public void configure() throws Exception {
LOG.info("Routing of camel is started");
CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
startPolicy.setRouteStartTime("0 0/5 * * * ?");
from(
"jms:queue:DLQ.Consumer.OUTDOCS.VirtualTopic.queue1")
.routeId("DLQMessageMoverID").routePolicy(startPolicy)
.noAutoStartup()
.to("jms:queue:Consumer.OUTDOCS.VirtualTopic.queue1");
LOG.info("Routing of camel is done");
}
}
@Startup
@Singleton
public class ScheduledMessageDLQConsumer {
@Inject
private MessagingUtil msgUtil;
@Inject
private MessageRouteBuilder builder;
private static final Logger LOG =
LoggerFactory.getLogger(ScheduledMessageDLQConsumer.class);
@PostConstruct
public void init() {
LOG.info("camel Scheduling scheduled started");
CamelContext camelContext = new DefaultCamelContext();
ConnectionFactory connectionFactory = msgUtil.getAMQConnectionFactory();
camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
try {
camelContext.addRoutes(builder);
camelContext.start();
LOG.info("Camel scheduling completed");
} catch (Exception e) {
// TODO Auto-generated catch block
LOG.error("Error in registering camel route builder", e);
}
LOG.info(" camel Scheduling scheduled completed");
}
}
Problem here is that:- Camel routing gets enabled after 5 minutes. It moves the message from DLQ (DLQ.Consumer.OUTDOCS.VirtualTopic.queue1) to queue1 (Consumer.OUTDOCS.VirtualTopic.queue1). But if message is poison , it again comes back to DLQ and again routing moves the message from DLQ to normal queue and this process keeps on running infinitely.
My requirement is that routing should move the message once only from DLQ to queue after every 5 minutes ? if poison message comes, it should check after 5 minutes only.