我有一个在 cloudfoundry 上的多个实例中运行的 spring 应用程序。 这些实例共享一个数据库。他们有一个 RabbitListener
配置如下:
@RabbitListener(queues = "${items.updated.queue}", exclusive = true)
如果需要从某个来源重新导入项目,队列会收到一条消息。
我只想要一个实例来执行导入。据我了解,这可以通过独占标志来实现。
现在,如果当前的 exclusive consumer
崩溃了会发生什么? 另一个当前正在运行的实例是否会将自己注册为新的 exclusive consumer
?还是仅在应用程序启动时才进行注册?
请您参考如下方法:
是的,另一个消费者将被授予访问权限。
消费者将重新尝试消费每 recoveryInterval
毫秒(默认 5000 - 5 秒)。
您可以通过在监听器容器中设置间隔或 recoveryBackoff
来更改此设置。
请注意,您将从容器中获取有关故障的 WARN 日志和来自连接工厂的 INFO 日志,表明 channel 因故障而关闭。
您可以调整日志级别以减少这些日志,或者您可以将自定义 ConditionalExceptionLogger
s 注入(inject)到容器和工厂中。
参见 the documentation .
If a consumer fails because one if its queues is being used exclusively, by default, as well as publishing the event, a WARN log is issued. To change this logging behavior, provide a custom
ConditionalExceptionLogger
in theSimpleMessageListenerContainer
'sexclusiveConsumerExceptionLogger
property. See also the section called “Logging Channel Close Events”.