如果RabbitMQ服务器暂时不可用,如何重试启动Apache Camel RabbitMQ消费者路由器

bxgwgixi  于 9个月前  发布在  Apache
关注(0)|答案(2)|浏览(75)

我有一个简单的Apache Camel 路线

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

示例项目是here
如果在我启动路由时RabbitMQ服务器已经启动并运行,那么一切都正常。问题是,如果RabbitMQ在路由启动时不可用,则路由启动会以org.springframework.amqp.AmqpConnectException终止。
有没有什么方法可以处理这个异常,并在一些延迟后重试几次,重新启动路由?
我试图添加onException,但似乎只适用于生产者(“到”端点)。
我还发现Apace Camel RoutePolicy.它的onInit方法在路由崩溃之前被触发,所以它可能会以某种方式用于重试路由启动,但文档不是很详尽,我也没有找到任何例子。

wvmv3b1j

wvmv3b1j1#

是,请参见监控路由控制器https://camel.apache.org/manual/route-controller.html
你也可以看看rabbitmq连接工厂(spring rabbitmq的东西),因为它可能也有某种内置的重试,你可以配置。

ldxq2e6h

ldxq2e6h2#

通过使用监督控制器(感谢@ClausIbsen),我通过在application.properties文件中添加以下行解决了这个问题

# Set Supervising controller
camel.springboot.route-controller-supervise-enabled = true

# and you can configure more options
camel.springboot.routeControllerBackoffDelay = 5000    
camel.springboot.routeControllerBackoffMaxAttempts = 3
camel.springboot.routeControllerInitialDelay = 1000
camel.springboot.routeControllerThreadPoolSize = 2

诀窍就是

camel.springboot.route-controller-enabled = true

documentation中所述,

camel.springboot.route-controller-supervise-enabled = true

相关问题