-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of Robust multi-channel consumer and publisher #13
Comments
It should technically be safe to re-open, but you will need to make sure that you only call connection.open when the connection is set to state CLOSED. If a connection is in state OPENING you need to make sure that the other threads are waiting.
Ideally though you would have a master thread that handles the connection, and the rest only handles the channels. If the connection goes down, the master thread re-connects, and the channels automatically re-open once the connection is established again. I'll see if I can add a robust multi-threaded example. |
A fairly straight forward example with 5 threaded consumers would look something like this.
|
I added an example that would be my recommended method of handling multiple threaded consumers. |
Thanks. Looks good.
|
That my friend is over engineering from my part. You can have multiple consumers on a single channel, and that piece of code checks if there is another thread consuming, if no other thread is consuming on that channel, it simply closes the channel. |
Awesome. Thanks! |
Whats the best way to reconnect when a channel errors?
Is it OK to call connection.open() to re-open a closed/errored connection? same for channel.open ?
Is it thread safe for multiple threads to try and re-open the connection on error?
Or do we need to pass around a connection wrapper that locks?
The text was updated successfully, but these errors were encountered: