wagslane / go-rabbitmq

A wrapper of streadway/amqp that provides reconnection logic and sane defaults
https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/
MIT License
805 stars 128 forks source link

when server side been maintained, the client will not reconnect success after server side start. #84

Closed busyfree closed 1 year ago

busyfree commented 2 years ago

how to handle when server side been maintained, the client will not reconnect success after server side start.

2022/08/09 03:07:15 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "read tcp IP:54358->IP:5075: i/o timeout"
2022/08/09 03:07:15 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/08/09 03:07:16 gorabbit WARN: successfully reconnected to amqp server
2022/08/09 03:07:16 gorabbit INFO: successful recovery from: Exception (501) Reason: "read tcp IP:54358->IP:5075: i/o timeout"
2022/08/09 03:07:16 gorabbit INFO: Processing messages on 10 goroutines
2022/08/10 13:03:52 gorabbit INFO: closing consumer...
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: amqp channel closed gracefully
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
2022/08/10 13:03:52 gorabbit INFO: rabbit consumer goroutine closed
wagslane commented 2 years ago

Sorry, can you be a bit more clear? This looks to me like the server restarted, the client successfully connected, but then you closed the client?

busyfree commented 2 years ago

the client not closed by manual, below is all the client reconnect log.

2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "write tcp 10.0.7.17:38128->169.254.0.168:5075: write: connection reset by peer"
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:44 gorabbit INFO: rabbit consumer goroutine closed
2022/10/08 02:03:45 gorabbit WARN: successfully reconnected to amqp server
2022/10/08 02:03:45 gorabbit INFO: successful recovery from: Exception (501) Reason: "write tcp 10.0.7.17:38128->169.254.0.168:5075: write: connection reset by peer"
2022/10/08 02:04:16 gorabbit ERROR: error restarting consumer goroutines after cancel or close: Exception (503) Reason: "unexpected command received"
2022/10/08 02:05:03 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "read tcp 10.0.7.17:35328->169.254.0.168:5075: i/o timeout"
2022/10/08 02:05:03 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:05:34 gorabbit ERROR: error reconnecting to amqp server: Exception (501) Reason: "read tcp 10.0.7.17:35436->169.254.0.168:5075: i/o timeout"
2022/10/08 02:05:34 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:05:50 gorabbit ERROR: error reconnecting to amqp server: Exception (403) Reason: "no access to this vhost"
2022/10/08 02:05:50 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:05:51 gorabbit WARN: successfully reconnected to amqp server
2022/10/08 02:05:51 gorabbit INFO: successful recovery from: Exception (501) Reason: "read tcp 10.0.7.17:35328->169.254.0.168:5075: i/o timeout"
2022/10/08 02:06:56 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "read tcp 10.0.7.17:35508->169.254.0.168:5075: i/o timeout"
2022/10/08 02:06:56 gorabbit ERROR: error restarting consumer goroutines after cancel or close: Exception (501) Reason: "read tcp 10.0.7.17:35508->169.254.0.168:5075: i/o timeout"
2022/10/08 02:06:56 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:07:27 gorabbit ERROR: error reconnecting to amqp server: Exception (501) Reason: "read tcp 10.0.7.17:35590->169.254.0.168:5075: i/o timeout"
2022/10/08 02:07:27 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:07:58 gorabbit ERROR: error reconnecting to amqp server: Exception (403) Reason: "no access to this vhost"
2022/10/08 02:07:58 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:08:29 gorabbit ERROR: error reconnecting to amqp server: Exception (501) Reason: "read tcp 10.0.7.17:35678->169.254.0.168:5075: i/o timeout"
2022/10/08 02:08:29 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:08:30 gorabbit WARN: successfully reconnected to amqp server
2022/10/08 02:08:30 gorabbit INFO: successful recovery from: Exception (501) Reason: "read tcp 10.0.7.17:35508->169.254.0.168:5075: i/o timeout"
2022/10/08 02:09:00 gorabbit ERROR: error restarting consumer goroutines after cancel or close: Exception (503) Reason: "unexpected command received"
2022/10/08 02:12:26 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "read tcp 10.0.7.17:35716->169.254.0.168:5075: i/o timeout"
2022/10/08 02:12:26 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:12:28 gorabbit WARN: successfully reconnected to amqp server
2022/10/08 02:12:28 gorabbit INFO: successful recovery from: Exception (501) Reason: "read tcp 10.0.7.17:35716->169.254.0.168:5075: i/o timeout"
2022/10/08 02:46:48 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (501) Reason: "read tcp 10.0.7.17:36032->169.254.0.168:5075: i/o timeout"
2022/10/08 02:46:48 gorabbit INFO: waiting 1s seconds to attempt to reconnect to amqp server
2022/10/08 02:46:48 gorabbit ERROR: error restarting consumer goroutines after cancel or close: Exception (501) Reason: "read tcp 10.0.7.17:36032->169.254.0.168:5075: i/o timeout"
2022/10/08 02:46:49 gorabbit WARN: successfully reconnected to amqp server
2022/10/08 02:46:49 gorabbit INFO: successful recovery from: Exception (501) Reason: "read tcp 10.0.7.17:36032->169.254.0.168:5075: i/o timeout"
2022/10/08 02:46:49 gorabbit INFO: Processing messages on 10 goroutines
wagslane commented 1 year ago

Please try out the new main branch version, it should work as you're describing