解決 RabbitMQ 叢集 Channel shutdown: connection error 錯誤(HAProxy 負載均衡)
阿新 • • 發佈:2019-01-15
具體錯誤資訊:
2018-05-04 11:21:48.116 ERROR 60848 --- [.168.0.202:8001] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: connection error
2018-05-04 11:21:48.116 ERROR 60848 --- [.168.0.202:8001] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: connection error
2018-05-04 11:21:48.125 INFO 60848 --- [nge.consumer1-8] o.s.a.r.l.SimpleMessageListenerContainer : Restarting [email protected]: tags=[{amq.ctag-d_wIlZIGxM3f0fsxkmYQfA=my_test_exchange.consumer1}], channel=Cached Rabbit Channel: AMQChannel(amqp://[email protected]:8001/,1), conn: [email protected] Shared Rabbit Connection: [email protected] [delegate=amqp://[email protected]:8001/, localPort= 56258], acknowledgeMode=AUTO local queue size=0
2018-05-04 11:21:48.126 INFO 60848 --- [nge.consumer1-9] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [manager1:8001]
2018-05-04 11:21:48.393 INFO 60848 --- [nge.consumer1-9] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#2b8bd14b:12/ [email protected] [delegate=amqp://[email protected]:8001/, localPort= 56260]
2018-05-04 11:21:49.059 INFO 60848 --- [nge.consumer1-8] o.s.a.r.l.SimpleMessageListenerContainer : Restarting [email protected]: tags=[{amq.ctag-T1HyrOd5Ykr_VQZDwxRslA=stream_exchange.consumer1}], channel=Cached Rabbit Channel: AMQChannel(amqp:// [email protected]:8001/,2), conn: [email protected] Shared Rabbit Connection: [email protected] [delegate=amqp://[email protected]:8001/, localPort= 56260], acknowledgeMode=AUTO local queue size=0
Spring Boot 配置 RabbitMQ(使用 HAProxy 負載均衡):
spring:
application:
name: stream-rabbitmq-producer
rabbitmq:
host: manager1
port: 8001
username: admin
password: admin123456
最近使用 RabbitMQ 叢集的時候(HAProxy 負載均衡),頻繁的出現上面錯誤資訊,但是訊息可以正常被消費掉,如果只使用單機版 RabbitMQ 的話(不使用 HAProxy),是沒有任何錯誤的。
文章說,如果使用 HAProxy 配置 RabbitMQ 高可用叢集的話,則會遇到客戶端連線超時問題。
為什麼會出現此問題呢?因為 HAProxy 配置了客戶端連線超時引數(timeout client ms
),如果客戶端連線超過配置的此引數,那麼 HAProxy 將會刪除這個客戶端連線。
RabbitMQ 客戶端使用永久連線到代理,從不超時,那為什麼還會出現問題?因為如果 RabbitMQ 在一段時間內處於非活動狀態,那麼 HAProxy 將自動關閉連線(有點坑呀