I have a Camel application that uses a timer to periodically check if a soap endpoint has messages waiting. If this is the case, these messages are consumed, transformed and put on an AMQ topic. I have two routes: 1 timerRoute that only contains the timer and a direct endpoint and 1 route that consumes the direct endpoint and processes the message. If the messages cannot be published on the topic because the broker is down (so if there’s an Exception when sending the message to the AMQ broker), I want the timer to stop checking for messages. After a certain period, the timer needs to start up again to retrieve a message and attempt to publish it to the broker again.
- Message loss is not permitted so the inflight message needs to be handled by an onException block that retries the message for a set time.
I tried to achieve this by using a combination of the circuitBreaker and the controlbus component in my second route:
from("direct:toCircuitbreakerRoute").id("processRouteCB")
.onException(ConnectException.class).id("onConnectException")
.process(logEndpointUnavailable)
.maximumRedeliveries(3)
.redeliveryDelay(10000)
.end()
.process(logMessageReceived)
.circuitBreaker()
.to(ExchangePattern.InOnly, "amqp:testTopic").id("toTopic")
.process(logMessageProcessed)
.onFallback()
.to("controlbus:route?routeId=timerRoute&action=stop&async=true")
.to("controlbus:route?routeId=timerRoute&action=restart&restartDelay=60000")
.end()
;
This works for stopping and restarting the route but the inflight message is lost.
Does anybody have any suggestions on how to achieve my goal?
If I try to catch the exception and use the controlbus to stop the route from there, the inflight message is still lost and the route won’t restart.
When I remove async=true, the message is still lost
KaNS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.