achilleasa / dart_amqp

Dart AMQP client implementing protocol version 0.9.1
MIT License
79 stars 40 forks source link

is there a client reconnect config? #42

Closed jingjiewei closed 4 years ago

jingjiewei commented 4 years ago

So after the network lost, the the client can connect to mq automatically?

achilleasa commented 4 years ago

Currently, automatic reconnect is not supported. However, you can implement this in your application by wrapping your code in a block that catches the raised connection exception, calls the connect method on the connection instance and runs your code again.

Note that as mentioned in the docs, if connect() fails to establish a link (e.g. due to transient network issues) it will wait and try again.

jingjiewei commented 4 years ago

Currently, automatic reconnect is not supported. However, you can implement this in your application by wrapping your code in a block that catches the raised connection exception, calls the connect method on the connection instance and runs your code again.

Note that as mentioned in the docs, if connect() fails to establish a link (e.g. due to transient network issues) it will wait and try again.

Thank a lot. Another question, in my customized "reconnect" method, is it possible to reuse the existing connection/channel/exchange/consumer? Since if it's a network issue, the old connection actually still exist. (Although in the plugin code, it will try to close the connection when the exception happens, but since network down, it will not take effect).

Really appreciate your help!

achilleasa commented 4 years ago

Please take a look at my response here. I think you will need to acquire a new channel and redefine your topology and any subscribers each time you reconnect.

jingjiewei commented 4 years ago

thanks, really helpful