【问题标题】:Close @RabbitListener channel before destroying在销毁之前关闭@RabbitListener 频道
【发布时间】:2018-12-16 15:47:20
【问题描述】:

我有以下监听组件:


@Component
public class Receiver {

    @RabbitListener(queues = "fmd-response")
    public void receiveMessage(Response response, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        channel.basicAck(tag, false);
    }

    @PreDestroy
    public void preDestroy() {

    }
}

应该在preDestroy() 中添加什么来关闭加载组件时自动创建的通道? 我需要这个来用 JRebel 重新加载组件,因为每次重新加载都会创建一个新通道:


127.0.0.1:54916 (1)
guest       idle    0   250 0               
127.0.0.1:54916 (2)
guest       idle    0   250 0               
127.0.0.1:54916 (3)
guest       idle    0   250 0               
127.0.0.1:54916 (4)
guest       idle    0   250 0               
127.0.0.1:54916 (5)
guest       idle    0   250 0               
127.0.0.1:54916 (6)
guest       idle    0   250 0

【问题讨论】:

    标签: rabbitmq spring-rabbit jrebel


    【解决方案1】:

    我不熟悉 JRebel;消费者的通道是长期存在的,当容器停止时会自动关闭()。

    也许当重新加载发生时容器没有停止?

    打开调试日志以查看容器/消费者/通道的活动。

    如果不清楚,请将完整的调试日志发布到 github gist 或 pastebin 之类的地方。

    您可以获得对RabbitListenerEndpointRegistry 的引用并尝试通过id 停止容器(给@RabbitListener 一个id)。

    【讨论】:

    • 我已将registry.getListenerContainers().forEach(Lifecycle::stop); 放入@PreDestroy 但没有任何效果,所以我认为JRebel 没有正确销毁bean。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 2012-06-09
    • 1970-01-01
    相关资源
    最近更新 更多