{"id":13509006,"url":"https://github.com/d0rc/exrabbit","last_synced_at":"2025-10-21T17:54:38.278Z","repository":{"id":10235199,"uuid":"12337519","full_name":"d0rc/exrabbit","owner":"d0rc","description":"Simple rabbitmq bindings for elixir","archived":false,"fork":false,"pushed_at":"2015-03-30T16:57:04.000Z","size":330,"stargazers_count":48,"open_issues_count":3,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-05T20:14:26.224Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Rundiz/opencart2-thai-language","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d0rc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-24T03:29:35.000Z","updated_at":"2023-09-01T08:47:57.000Z","dependencies_parsed_at":"2022-09-19T01:10:11.572Z","dependency_job_id":null,"html_url":"https://github.com/d0rc/exrabbit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/d0rc/exrabbit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0rc%2Fexrabbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0rc%2Fexrabbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0rc%2Fexrabbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0rc%2Fexrabbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d0rc","download_url":"https://codeload.github.com/d0rc/exrabbit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d0rc%2Fexrabbit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280308477,"owners_count":26308492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:01:01.671Z","updated_at":"2025-10-21T17:54:38.227Z","avatar_url":"https://github.com/d0rc.png","language":"Elixir","funding_links":[],"categories":["Queue"],"sub_categories":[],"readme":"# Exrabbit\n\nEdited to handle more option in exchanges / queues. Major work done by d0rc\n\n\nEasy way to get a queue/exchange worker:\n\n\n```elixir\nimport Exrabbit.DSL\n\namqp_worker TestQ, queue: \"testQ\" do\n  on json = %{} do\n    IO.puts \"JSON: #{inspect json}\"\n  end\n  on \u003c\u003c\"hello\"\u003e\u003e do\n    IO.puts \"Hello-hello from MQ\"\n  end\n  on text do\n    IO.puts \"Some random binary: #{inspect text}\"\n  end\nend\n```\n\nN.B. Instead of passing configuration options when defining module with `amqp_worker` one can add following to config.exs:\n\n```elixir\n[\n  exrabbit: [\n    my_queue: [queue: \"TestQ\"]\n  ]\n]\n```\n\nand then define module as:\n\n\n```elixir\namqp_worker TestQ, config_name: :my_queue, decode_json: [keys: :atoms] do\n  on %{cmd: \"resize_image\", image: image} do\n    IO.puts \"Resizing image: #{inspect image}\"\n  end\nend\n```\n\n\nChecking if message was published:\n\n\n```elixir\npublish(channel, exchange, routing_key, message, :wait_confirmation)\n```\n\n\nWorkflow to send message:\n\n\n```elixir\namqp = Exrabbit.Utils.connect\nchannel = Exrabbit.Utils.channel amqp\nExrabbit.Utils.publish channel, \"testExchange\", \"\", \"hello, world\"\n```\n\n\nTo get messages, almost the same, but functions are\n\n\n```elixir\nExrabbit.Utils.get_messages channel, \"testQueue\"\ncase Exrabbit.Utils.get_messages_ack channel, \"testQueue\" do\n\tnil -\u003e IO.puts \"No messages waiting\"\n\t[tag: tag, content: message] -\u003e \n\t\tIO.puts \"Got message #{message}\"\n\t\tExrabbit.Utils.ack tag # acking message\nend\n```\n\n\nPlease consult: http://www.rabbitmq.com/erlang-client-user-guide.html#returns to find out how to write gen_server consuming messages.\n\n\n```elixir\ndefmodule Consumer do\n  use GenServer.Behaviour\n  import Exrabbit.Utils\n  require Lager\n\n  def start_link, do: :gen_server.start_link(Consumer, [], [])\n\n  def init(_opts) do\n    amqp = connect\n    channel = channel amqp\n    subscribe channel, \"testQ\"\n    {:ok, [connection: amqp, channel: channel]}\n  end\n\n  def handle_info(request, state) do\n    case parse_message(request) do\n      nil -\u003e Lager.info \"Got nil message\"\n      {tag, payload} -\u003e\n        Lager.info \"Got message with tag #{tag} and payload #{payload}\"\n        ack state[:channel], tag\n    end\n    { :noreply, state}\n  end\nend\n```\n\n\nOr same, using behaviours:\n\n\n```elixir\ndefmodule Test do \n  use Exrabbit.Subscriber \n\n  def handle_message(msg, _state) do \n    case parse_message(msg) do \n      nil -\u003e \n        IO.puts \"Nil\"\n      {tag,json} -\u003e \n        IO.puts \"Msg: #{json}\"\n        ack _state[:channel], tag \n      {tag,json,reply_to} -\u003e \n        IO.puts \"For RPC messaging: #{json}\"\n        publish(_state[:channel], \"\", reply_to, \"#{json}\") # Return ECHO\n        ack _state[:channel], tag \n    end  \n  end \nend\n\n:gen_server.start Test, [queue: \"testQ\"], []   \n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd0rc%2Fexrabbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd0rc%2Fexrabbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd0rc%2Fexrabbit/lists"}