Spring 当独占使用者失败时,要处理哪个AmqpEvent或AmqpException

Spring 当独占使用者失败时,要处理哪个AmqpEvent或AmqpException,spring,spring-boot,spring-amqp,spring-rabbit,Spring,Spring Boot,Spring Amqp,Spring Rabbit,我有两个相同应用程序的实例,运行在不同的虚拟机上。我想为其中一个用户授予对队列的独占访问权,同时使另一个用户使用的本地缓存无效 现在,我已经知道我需要处理这个事件,但是我猜想,由于独占消费者异常,为这个事件实现ApplicationListener并不能确保我收到这个事件。我可能想检查事件的可丢弃性,或者进一步检查事件 AmqpException的哪个子类或我应该执行哪些进一步的检查以确保由于独占使用者访问而接收到异常?侦听器容器实现中的逻辑如下所示: if (e.getCause() inst

我有两个相同应用程序的实例,运行在不同的虚拟机上。我想为其中一个用户授予对队列的独占访问权,同时使另一个用户使用的本地缓存无效

现在,我已经知道我需要处理这个事件,但是我猜想,由于独占消费者异常,为这个事件实现ApplicationListener并不能确保我收到这个事件。我可能想检查事件的可丢弃性,或者进一步检查事件


AmqpException的哪个子类或我应该执行哪些进一步的检查以确保由于独占使用者访问而接收到异常?

侦听器容器实现中的逻辑如下所示:

if (e.getCause() instanceof ShutdownSignalException
            && e.getCause().getMessage().contains("in exclusive use")) {
        getExclusiveConsumerExceptionLogger().log(logger,
                "Exclusive consumer failure", e.getCause());
        publishConsumerFailedEvent("Consumer raised exception, attempting restart", false, e);
    }
因此,我们确实引发了ListenerContainerConsumerFailedEvent事件,您可以像我们在框架中一样跟踪原因消息,但另一方面,您可以插入自己的ConditionalExceptionLogger:

在那里抓住这样一个独家的情况

您也可以考虑使用Rabtuuts.代码中的IsExabsivEuthChhanelCouthEclipse:

/**
 * Return true if the {@link ShutdownSignalException} reason is AMQP.Channel.Close
 * and the operation that failed was basicConsumer and the failure text contains
 * "exclusive".
 * @param sig the exception.
 * @return true if the declaration failed because of an exclusive queue.
 */
public static boolean isExclusiveUseChannelClose(ShutdownSignalException sig) {

非常感谢。我知道我可以使用ConditionalExceptionLogger,但我选择的方法在词汇上似乎更为正确。如何从ListenerContainerConsumerFailedEvent获取关机信号异常。在一瞬间检查后,将其扔掉会起作用吗?这是正确的,但一定是原因。请参阅上文提到的ife.getCause instanceof ShutdowsSignalException。
/**
 * Return true if the {@link ShutdownSignalException} reason is AMQP.Channel.Close
 * and the operation that failed was basicConsumer and the failure text contains
 * "exclusive".
 * @param sig the exception.
 * @return true if the declaration failed because of an exclusive queue.
 */
public static boolean isExclusiveUseChannelClose(ShutdownSignalException sig) {