Close Idle/dangling channels

I have a multi-threaded application that publishes incoming messages to a rabbitmq exchange. Using the rabbitmq java client, I create a single rabbitmq connection at application startup and share it across all my threads. Each thread creates a new channel (threadlocal) so that the channels are not shared across multiple threads as recommended by the rabbitmq documentation. I am using netty and I see the same number of rabbitmq channels being created as netty channel pipeline threads. So far so good.

However, I have a keep alive time of 2 mins on my netty threads (I need this and cannot change it). So, if a thread is idle for 2 mins it dies. However, the channel associated to the thread isn't killed and remains idle until the connection closes. Thus, I get an increasing list of channels that are IDLE and never get closed. I did not see anything in rabbitmq documentation that addresses the issue of dangling channels. Is there a way for me to close a channel that has been idle for a period of time? If not, what's the best alternative to resolve this?


Actually there is no way to close the channel from the web-console as the channel is bound to the connection. So what you can do is go to the Connections tab, click on the connection (it has same id as the channel, so it's easy to identify) and on the opened page click Force Close


You could use the RabbitMQ Management HTTP API and list then channels, then on the details of each channel you can see since when the channel is idle, and react accordingly, closing the channel for example.

See here: http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html


I had a similar requirement. It has been a while so I don't remember where I found the information about it. But this is how I closed my channel.

    if (cancellationToken.IsCancellationRequested)
    {
         logger.InfoFormat("Cancellation requested, stopping case processor.");

         // 320: connection-forced
         channel.Close(320, "Service stopped");
     }
链接地址: http://www.djcxy.com/p/34098.html

上一篇: spring集成amqp通道错误处理程序auto ack

下一篇: 关闭空闲/悬空通道