1. 程式人生 > >com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed

com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed

場景:rabbitMQ生產者釋出訊息。

程式碼【java】:

channel.basicPublish("exchangeTest111", "testQueue1", null, "hahaha".getBytes());

產生異常:

com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel
    at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:190)
    at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:291)
    at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:634)
    at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:617)
    at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:608)
    at rabbitMQ.Sender.main(Sender.java:52)

異常原因:channel被關閉。因為向一個不存在的exchange發訊息。


其他可能產生channel被關閉的原因請參考:http://stackoverflow.com/questions/8839094/why-do-my-rabbitmq-channels-keep-closing