简体   繁体   English

如何断开连接,然后使用EasyNetQ从RabbitMQ重新连接?

[英]How to disconnect, then reconnect from RabbitMQ using EasyNetQ?

I am in a situation where I need to disconnect from RabbitMQ and reconnect using EasyNetQ. 我处于需要断开与RabbitMQ的连接并使用EasyNetQ重新连接的情况。 I'm doing this by disposing of IBus as described in the documentation. 我是通过处理文档中描述的IBus来做到这一点的。

https://github.com/EasyNetQ/EasyNetQ/wiki/connecting-to-rabbitmq https://github.com/EasyNetQ/EasyNetQ/wiki/connecting-to-rabbitmq

"To close the connection, simply dispose the bus ... This will close the connection, channels, consumers and all other resources used by EasyNetQ." “要关闭连接,只需处理总线......这将关闭EasyNetQ使用的连接,通道,消费者和所有其他资源。”

However when I make the call to create a new bus, it is still shown as disconnected and disposed. 但是,当我打电话来创建一个新的总线时,它仍然显示为断开连接并处理掉。

bus = RabbitHutch.CreateBus(connString);
bus.Dispose();
resolver.EasyNetQKernel.Release(bus);
bus = RabbitHutch.CreateBus(connString);
bus.Receive<Command>("CommandQueue"), Process);

At this point when I try to reset my consumers, I get an EasyNetQException with the message "Bus has been disposed." 此时,当我尝试重置我的消费者时,我收到一条EasyNetQException,其中显示“Bus已被丢弃”。

Why can I not recreate the bus after disposing of it? 为什么我不能在处理它后重新创建总线?

I haven't used Ninject, but could you try disposing and recreating your whole Ninject container instead of the bus instance? 我没有使用Ninject,但你可以尝试处理和重新创建整个Ninject容器而不是总线实例吗? I think your container might be holding on to old references that are already disposed. 我认为您的容器可能会保留已经处理的旧引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM