[rabbitmq-discuss] Java client: Closing channel in channel shutdown listener
simon at rabbitmq.com
Thu Nov 4 11:10:57 GMT 2010
On 03/11/10 15:39, jiri at krutil.com wrote:
>> Hi Jiri. The shutdown listener is invoked by the connection's mainloop
>> thread, so it can't in itself do anything that involves sending data
>> over the connection (which includes closing channels).
> OK. Can I close the connection from a channel shutdown listener?
Not directly; it has the same problem. Of course, you could just spin up
a short-lived thread to do the closing in either case.
>> Do you need to close channels? If the error is hard, the connection
>> will be closed and implicitly all channels will close; if the error is
>> soft only the channel that caused the error will close and the others
>> will keep working.
> I have a few long-lived channels in my app. If any of them gets closed
> due to an error (maybe I attempt to publish to a nonexistent exchange),
> I want to close everything, re-connect and re-open my channels. This is
> to avoid a situation when a closed channel causes that part of the app
> does not work, trying to use a closed channel over and over again.
Right. Of course, you could just reopen the channel that closed, but
your approach may be simpler.
> So I guess the easiest way to go for me is: in the channel shutdown
> listener, close the connection without trying to close channels, then
If you close the connection the channels get closed implicitly. But as
noted above, you'll need to do that in a different thread.
Staff Engineer, RabbitMQ
SpringSource, a division of VMware
More information about the rabbitmq-discuss