public final void retryFailedMessages() {
log.trace("retrying failed messages ... ");
long startTime = new Date().getTime();
MessageStore messageStore = resourceRegistry.getResource(MessageStore.class);
ProducerTemplate producer = camelContext.createProducerTemplate();
MessageCriteria criteria = new MessageCriteria()
.addStatus(Message.STATUS_FAILED)
.orderBy("creation_time")
.orderType(OrderType.UPWARDS);
Collection<Message> messages = messageStore.list(criteria);
logCollectionSize(messages.size()); // log the size of the collection
for (Message message : messages) {
// update the message and send it
message.setStatus(Message.STATUS_RETRYING);
message.setModificationTime(new Date());
messageStore.saveOrUpdate(message);
if (message.getDirection().equals(Direction.TO_CONNECTIONS)) {
producer.sendBody(UriConstants.CONNECTIONS_ROUTER, ExchangePattern.InOnly, message);
} else if (message.getDirection().equals(Direction.TO_APPLICATIONS)) {
producer.sendBody(UriConstants.APPLICATIONS_ROUTER, ExchangePattern.InOnly, message);