{"action":"created","issue":{"url":"https://api.github.com/repos/pma/amqp/issues/8","labels_url":"https://api.github.com/repos/pma/amqp/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/pma/amqp/issues/8/comments","events_url":"https://api.github.com/repos/pma/amqp/issues/8/events","html_url":"https://github.com/pma/amqp/pull/8","id":70943085,"number":8,"title":"adding return and confirmation handlers","user":{"login":"marcelog","id":527356,"avatar_url":"https://avatars.githubusercontent.com/u/527356?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelog","html_url":"https://github.com/marcelog","followers_url":"https://api.github.com/users/marcelog/followers","following_url":"https://api.github.com/users/marcelog/following{/other_user}","gists_url":"https://api.github.com/users/marcelog/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelog/subscriptions","organizations_url":"https://api.github.com/users/marcelog/orgs","repos_url":"https://api.github.com/users/marcelog/repos","events_url":"https://api.github.com/users/marcelog/events{/privacy}","received_events_url":"https://api.github.com/users/marcelog/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-25T17:42:46Z","updated_at":"2015-04-26T00:16:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pma/amqp/pulls/8","html_url":"https://github.com/pma/amqp/pull/8","diff_url":"https://github.com/pma/amqp/pull/8.diff","patch_url":"https://github.com/pma/amqp/pull/8.patch"},"body":"Hello,\r\n\r\nI couldn't find these features in the code, so maybe I'm missing something (or maybe not). This pull adds the capability of registering a confirmation handler and a return handler, when one wants to follow up on what happened with the sent messages on a more customized way. I hope you're ok with the location for the functions.\r\n\r\nThanks in advance!"},"comment":{"url":"https://api.github.com/repos/pma/amqp/issues/comments/96298138","html_url":"https://github.com/pma/amqp/pull/8#issuecomment-96298138","issue_url":"https://api.github.com/repos/pma/amqp/issues/8","id":96298138,"user":{"login":"marcelog","id":527356,"avatar_url":"https://avatars.githubusercontent.com/u/527356?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelog","html_url":"https://github.com/marcelog","followers_url":"https://api.github.com/users/marcelog/followers","following_url":"https://api.github.com/users/marcelog/following{/other_user}","gists_url":"https://api.github.com/users/marcelog/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelog/subscriptions","organizations_url":"https://api.github.com/users/marcelog/orgs","repos_url":"https://api.github.com/users/marcelog/repos","events_url":"https://api.github.com/users/marcelog/events{/privacy}","received_events_url":"https://api.github.com/users/marcelog/received_events","type":"User","site_admin":false},"created_at":"2015-04-26T00:16:16Z","updated_at":"2015-04-26T00:16:16Z","body":"The code looks something like this for the return handler with an adapter process. When calling the `register_return_handler`, a new process is spawned and it will receive the messages and send something similar to what a consume action sends, `{:basic_return, payload, amqp_msg}`:\r\n\r\n```elixir\r\n  @doc \"\"\"\r\n  Registers a process as a return handler for the given channel.\r\n  \"\"\"\r\n  def register_return_handler(chan = %Channel{pid: pid}, handler_pid) do\r\n    adapter_pid = spawn fn ->\r\n      Process.flag(:trap_exit, true)\r\n      Process.monitor(handler_pid)\r\n      Process.monitor(chan.pid)\r\n      do_return_handler(chan, handler_pid)\r\n    end\r\n    :amqp_channel.register_return_handler(pid, adapter_pid)\r\n  end\r\n\r\n  defp do_return_handler(chan, handler_pid) do\r\n    receive do\r\n      {basic_return(\r\n        reply_code: reply_code,\r\n        reply_text: reply_text,\r\n        exchange: exchange,\r\n        routing_key: routing_key\r\n      ), amqp_msg(props: p_basic(content_type: content_type,\r\n                               content_encoding: content_encoding,\r\n                               headers: headers,\r\n                               delivery_mode: delivery_mode,\r\n                               priority: priority,\r\n                               correlation_id: correlation_id,\r\n                               reply_to: reply_to,\r\n                               expiration: expiration,\r\n                               message_id: message_id,\r\n                               timestamp: timestamp,\r\n                               type: type,\r\n                               user_id: user_id,\r\n                               app_id: app_id,\r\n                               cluster_id: cluster_id\r\n      ), payload: payload)} ->\r\n        send handler_pid, {:basic_return, payload, %{\r\n                                          reply_code: reply_code,\r\n                                          reply_text: reply_text,\r\n                                          exchange: exchange,\r\n                                          routing_key: routing_key,\r\n                                          content_type: content_type,\r\n                                          content_encoding: content_encoding,\r\n                                          headers: headers,\r\n                                          delivery_mode: delivery_mode,\r\n                                          priority: priority,\r\n                                          correlation_id: correlation_id,\r\n                                          reply_to: reply_to,\r\n                                          expiration: expiration,\r\n                                          message_id: message_id,\r\n                                          timestamp: timestamp,\r\n                                          type: type,\r\n                                          user_id: user_id,\r\n                                          app_id: app_id,\r\n                                          cluster_id: cluster_id\r\n\r\n        }}\r\n        do_return_handler(chan, handler_pid)\r\n      {:DOWN, _ref, :process, ^handler_pid, reason} ->\r\n        unregister_return_handler(chan)\r\n        exit(reason)\r\n      {:DOWN, _ref, :process, _pid, reason} ->\r\n        unregister_return_handler(chan)\r\n        exit(reason)\r\n    end\r\n  end\r\n```\r\n\r\nQuestion: When calling `unregister_return_handler` this new adapter process should die. When consuming, there's the cancel message, but we don't have something like that in this case. How would you like to handle this scenario?"}}