rabbitmqapache-camelspring-rabbit

How to retry starting Apache Camel RabbitMQ consumer router if the RabbitMQ server is temporarily unavailable


I have a simple Apache Camel route

     from("spring-rabbitmq:myExchange?routingKey=foo&bridgeErrorHandler=true")
        .log("From RabbitMQ: ${body}");

The sample project is here.

If the RabbitMQ server is up and running when I start the route, everything works fine. The problem is if the RabbitMQ is not available on the route start the route startup terminates with org.springframework.amqp.AmqpConnectException.

Is there any way how to handle the exception and retry several times after some delay starting the route again?

I tried to add onException but that seems to work for producer ("to" endpoint) only.

I have also found Apace Camel RoutePolicy. It's method onInit is triggered before the route crashes so it might be used somehow to retry the route startup but the documentation is not very exhausting and I have not found any example either.


Solution

  • Yes see supervising route controller https://camel.apache.org/manual/route-controller.html

    Also you may look at the rabbitmq connection factory (spring rabbitmq stuff) as it may have some kind of retry built-in as well, you can configure.