-
Notifications
You must be signed in to change notification settings - Fork 123
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
Detecting Connection and Channel Down #31
Comments
@mvbaffa Hi, AMQP.Connection.open will not link your caller process to the connection pid. One way to detect disconnects and implement reconnects is described in https://github.com/pma/amqp#stable-rabbitmq-connection. If you force close the connection on the server side, the connection pid will die and if you monitor it you can react and start a new connection. Handling reconnects directly by the Supervisor restart mechanism is usually not the best approach. The restarts will happen so fast that the max retries of your supervisor will be exceeded. This will cause the supervisor to crash and cascade the failure, bringing the entire app down (see http://ferd.ca/it-s-about-the-guarantees.html). |
Hi, I am using exactly the same code you have suggested. the only difference is that a do not have an exchange after the Basic.qos a I declare my queue. Look:
And
The startProcessing will call rabbitmq_connect. But the message down does not arrives. I have a catch all handle_info too and nothing ... Thanks |
@mvbaffa You are probably missing a call to |
No. It did not work. Same thing |
@mvbaffa If you can share a git repo with a minimum example that replicates the issue, I can take a look at it and try to figure out why it's not working. |
Our repo is private. I will send you the files if you do not care The wait_for_messages is piece of code taken from the RabbitMQ site and rabbitmq_connect from your site. I can receive messages normally but there are two problems:
I have included the trap_exit in the init of MM.Queue.TransactionAvaiable but the problem continues Sorry, maybe the solution is trivial but I am new to elixir. This is probably a newbye issue. Thank you very much
|
@mvbaffa Your When using the GenServer behaviour, the receive loop is implemented in the "generic" module. Your "specific" module should only implement the callbacks functions. You shouldn't do receive loop of your own if you are implementing a GenServer behaviour. To make it work as intended, make sure that after successfully connecting, your init actually returns {:ok, state}, where state is whatever state you need to maintain and pass around handler functions (the conn, chan, etc..). Handling the def handle_info({:basic_deliver, payload, meta}, your_state) do
# Process message
{:noreply, your_state}
end And if after successfully connecting you want to receive a signal when the connection dies, you must enable the trap_exit flag in your init: def init(_args) do
Process.flag(: trap_exit, true)
# Initialize
{:ok, initial_state}
end This post (http://beatscodeandlife.ghost.io/understanding-genserver-with-elixir/) tries to explain how the GenServer behaviour works under the hood. I think it could help clarify some of my notes above. |
I will change the code and as soon as it works I will let you know. Thank you |
Hi,
I would like to know how can I trace the errors when the connection or channel are down.
I have a supervisor of my module and I can open and read messages from a queue.
If I go to Rabbit Management application and kill my connection I receive the message:
[warn] Connection (#PID<0.158.0>) closing: received hard error {:"connection.close", 320, "CONNECTION_FORCED - Closed via management plugin",
0, 0} from server
But the Supervisor does not instantiates a new process. My handle_info is mattching basic_cancel, basic_cancel_ok and a Catch all. By the way the same Supervisor works when my GenEvent Handler crashes.
Why none of the handle info where selected ?
The text was updated successfully, but these errors were encountered: