jfu
jfu

Reputation: 1700

Handling connection failures in apache-camel

I am writing an apache-camel RabbitMQ consumer. I would like to react somehow to connection problems (i.e. try to reconnect). Is it possible to configure apache-camel to automatically reconnect?

If not, how can I find out that a connection to the queue was interrupted? I've done the following test:

I am using camel in Scala (via akka-camel), but a Java solution would be probably also OK

Upvotes: 5

Views: 2314

Answers (3)

Jonathan
Jonathan

Reputation: 5107

For automatic RabbitMQ resource recovery (Connections/Channels/Consumers/Queues/Exchanages/Bindings) when failures occur, check out Lyra (which I authored). Example usage:

Config config = new Config()
  .withRecoveryPolicy(new RecoveryPolicy()
    .withMaxAttempts(20)
    .withInterval(Duration.seconds(1))
    .withMaxDuration(Duration.minutes(5)));
ConnectionOptions options = new ConnectionOptions().withHost("localhost");
Connection connection = Connections.create(options, config);

The rest of the API is just the amqp-client API, except your resources are automatically recovered when failures occur.

I'm not sure about camel-rabbitmq specifically, but hopefully there's a way you can swap in your own resource creation via Lyra.

Upvotes: 1

Jimmy Au
Jimmy Au

Reputation: 2073

You can pass in the flag automaticRecoveryEnabled=true to the URI, Camel will reconnect if the connection is lost.

Upvotes: 2

Willem Jiang
Willem Jiang

Reputation: 3291

Current camel-rabbitmq just create a connection and the channel when the consumer or producer is started. So it don't have a chance to catch the connection exception :(.

Upvotes: 0

Related Questions