{"id":13509010,"url":"https://github.com/meltwater/gen_rmq","last_synced_at":"2025-03-30T13:31:16.774Z","repository":{"id":37444268,"uuid":"125196283","full_name":"meltwater/gen_rmq","owner":"meltwater","description":"Elixir AMQP consumer and publisher behaviours","archived":true,"fork":false,"pushed_at":"2023-05-25T13:29:41.000Z","size":326,"stargazers_count":181,"open_issues_count":16,"forks_count":44,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-05-01T15:46:47.400Z","etag":null,"topics":["abstraction","amqp","behaviours","clientdata-no","elixir","lifecycle-sunset","otp","production-dependency","purpose-library","rabbitmq","testing","usage-application"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meltwater.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-03-14T10:35:37.000Z","updated_at":"2024-01-19T18:22:21.000Z","dependencies_parsed_at":"2024-01-31T07:53:46.564Z","dependency_job_id":null,"html_url":"https://github.com/meltwater/gen_rmq","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fgen_rmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fgen_rmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fgen_rmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fgen_rmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meltwater","download_url":"https://codeload.github.com/meltwater/gen_rmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222552311,"owners_count":17002039,"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","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":["abstraction","amqp","behaviours","clientdata-no","elixir","lifecycle-sunset","otp","production-dependency","purpose-library","rabbitmq","testing","usage-application"],"created_at":"2024-08-01T02:01:01.730Z","updated_at":"2024-11-01T09:30:18.000Z","avatar_url":"https://github.com/meltwater.png","language":"Elixir","funding_links":[],"categories":["Queue"],"sub_categories":[],"readme":"[![Build Status](https://github.com/meltwater/gen_rmq/workflows/GenRMQ%20CI/badge.svg)](https://github.com/meltwater/gen_rmq/actions?query=workflow%3A%22GenRMQ+CI%22)\n[![Hex Version](http://img.shields.io/hexpm/v/gen_rmq.svg)](https://hex.pm/packages/gen_rmq)\n[![Coverage Status](https://coveralls.io/repos/github/meltwater/gen_rmq/badge.svg?branch=master)](https://coveralls.io/github/meltwater/gen_rmq?branch=master)\n[![Hex.pm Download Total](https://img.shields.io/hexpm/dt/gen_rmq.svg?style=flat-square)](https://hex.pm/packages/gen_rmq)\n[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\u0026repo=meltwater/gen_rmq)](https://dependabot.com)\n\n# GenRMQ\n\nGenRMQ is a set of [behaviours][behaviours] meant to be used to create\nRabbitMQ consumers and publishers, as fully OTP compliant GenServers.\n\nInternally it is using the [AMQP][amqp] elixir RabbitMQ client. The idea\nis to reduce boilerplate consumer / publisher code, which usually\nincludes:\n\n- creating connection / channel and keeping it in a state\n- creating and binding queue\n- handling reconnections / consumer cancellations\n\nGenRMQ provides the following functionality:\n\n- `GenRMQ.Consumer` - a behaviour for implementing RabbitMQ consumers ([example][example_consumer])\n- `GenRMQ.Publisher` - a behaviour for implementing RabbitMQ publishers ([example][example_publisher])\n- `GenRMQ.Processor` - a behaviour for implementing RabbitMQ message processors (this is useful to separate out business logic from your consumer) ([example][example_processor])\n- `GenRMQ.Consumer.Telemetry` - telemetry events emitted by a GenRMQ consumer\n- `GenRMQ.Publisher.Telemetry` - telemetry events emitted by a GenRMQ publisher\n- `GenRMQ.RabbitCase` - test utilities for RabbitMQ ([example][example_rabbit_case])\n\n## Installation\n\nGenRMG requires Elixir 1.11 or newer, running on at least OTP 22.\n\n```elixir\ndef deps do\n  [{:gen_rmq, \"~\u003e 4.0\"}]\nend\n```\n\n## Migrations\n\nVersion `4.0.0` has been released. Please check [how to migrate to gen_rmq `4.0.0`][migrating_to_400].\n\n## Examples\n\nMore thorough examples for using `GenRMQ.Consumer`, `GenRMQ.Publisher`, and `GenRMQ.Processor`\ncan be found under [documentation][examples].\n\n### Consumer\n\n```elixir\ndefmodule Consumer do\n  @behaviour GenRMQ.Consumer\n\n  @impl GenRMQ.Consumer\n  def init() do\n    [\n      queue: \"gen_rmq_in_queue\",\n      exchange: \"gen_rmq_exchange\",\n      routing_key: \"#\",\n      prefetch_count: \"10\",\n      connection: \"amqp://guest:guest@localhost:5672\",\n      retry_delay_function: fn attempt -\u003e :timer.sleep(2000 * attempt) end\n    ]\n  end\n\n  @impl GenRMQ.Consumer\n  def consumer_tag() do\n    \"test_tag\"\n  end\n\n  @impl GenRMQ.Consumer\n  def handle_message(message) do\n    ...\n  end\n\n  @impl GenRMQ.Consumer\n  def handle_error(message, _reason) do\n    GenRMQ.Consumer.reject(message, true)\n  end\nend\n```\n\n```elixir\nGenRMQ.Consumer.start_link(Consumer, name: Consumer)\n```\n\nThis will result in:\n\n- durable `gen_rmq_exchange.deadletter` exchange created or redeclared\n- durable `gen_rmq_in_queue_error` queue created or redeclared. It will be bound to `gen_rmq_exchange.deadletter`\n- durable topic `gen_rmq_exchange` exchange created or redeclared\n- durable `gen_rmq_in_queue` queue created or redeclared. It will be bound to `gen_rmq_exchange` exchange and has a deadletter exchange set to `gen_rmq_exchange.deadletter`\n- every `handle_message` callback will be executed in a separate supervised Task. This can be disabled by setting `concurrency: false` in `init` callback\n- on failed rabbitmq connection it will wait for a bit and then reconnect\n\nThere are many options to control the consumer setup details, please check the `c:GenRMQ.Consumer.init/0` [docs][consumer_doc] for all available settings.\n\n### Publisher\n\n```elixir\ndefmodule Publisher do\n  @behaviour GenRMQ.Publisher\n\n  def init() do\n    [\n      exchange: \"gen_rmq_exchange\",\n      connection: \"amqp://guest:guest@localhost:5672\"\n    ]\n  end\nend\n```\n\n```elixir\nGenRMQ.Publisher.start_link(Publisher, name: Publisher)\nGenRMQ.Publisher.publish(Publisher, Jason.encode!(%{msg: \"msg\"}))\n```\n\n## Documentation\n\n### Examples\n\n- [Consumer][example_consumer]\n- [Publisher][example_publisher]\n- [Processor][example_processor]\n\n### Guides\n\n- [Basic consumer setup][guide_consumer_basic_setup]\n- [Consumer with custom deadletter configuration][guide_consumer_with_custom_deadletter_configuration]\n- [Consumer with custom exchange type][guide_consumer_with_custom_exchange_type]\n- [Consumer with custom queue configuration][guide_consumer_with_custom_queue_configuration]\n- [Consumer without deadletter configuration][without_deadletter_configuration]\n- [Consumer with quorum queues][with_quorum_queue_type]\n\n### Metrics\n\n- [Consumer Telemetry events][consumer_telemetry_events]\n- [Publisher Telemetry events][publisher_telemetry_events]\n\n### Migrations\n\n- [Version 1.0.0][migrating_to_100]\n- [Version 3.0.0][migrating_to_300]\n- [Version 4.0.0][migrating_to_400]\n\n## Running Tests\n\nYou need [docker-compose][docker_compose] installed.\n\n```bash\n$ make test\n```\n\n## How to Contribute\n\nPlease see our [Contribution Guidelines](CONTRIBUTING.md).\n\nAre you using GenRMQ in Production? Please let us know, we are curious to learn about your experiences!\n\n## Maintainers\n\n- Mateusz ([@mkorszun](https://github.com/mkorszun))\n\nThe maintainers are responsible for the general project oversight, and empowering further trusted committers (see below).\n\nThe maintainers are the ones that create new releases of GenRMQ.\n\n## Trusted Committers\n\n- Joel ([@vorce](https://github.com/vorce))\n- [@Shemeikka](https://github.com/Shemeikka)\n- Alexander ([@akoutmos](https://github.com/akoutmos))\n- (alumnus) Sebastian ([@spier](https://github.com/spier))\n\nTrusted Committers are members of our community who we have explicitly added to our GitHub repository. Trusted Committers have elevated rights, allowing them to send in changes directly to branches and to approve Pull Requests. For details see [TRUSTED-COMMITTERS.md][trusted_commiters].\n\n_Note:_ Maintainers and Trusted Committers are listed in [.github/CODEOWNERS][code_owners] in order to automatically assign PR reviews to them.\n\n## License\n\nThe [MIT License][license].\n\nCopyright (c) Meltwater Inc. [underthehood.meltwater.com][underthehood]\n\n[behaviours]: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html#behaviours\n[amqp]: https://github.com/pma/amqp\n[migrating_to_100]: https://github.com/meltwater/gen_rmq/blob/master/documentation/migrations/1.0.0.md\n[migrating_to_300]: https://github.com/meltwater/gen_rmq/blob/master/documentation/migrations/3.0.0.md\n[migrating_to_400]: https://github.com/meltwater/gen_rmq/blob/master/documentation/migrations/4.0.0.md\n[consumer_doc]: https://github.com/meltwater/gen_rmq/blob/master/lib/consumer.ex\n[docker_compose]: https://docs.docker.com/compose/\n[github_prs]: https://help.github.com/articles/about-pull-requests/\n[gen_rmq_issues]: https://github.com/meltwater/gen_rmq/issues\n[priority_queues]: https://www.rabbitmq.com/priority.html\n[underthehood]: http://underthehood.meltwater.com/\n[examples]: https://github.com/meltwater/gen_rmq/blob/master/documentation/examples\n[example_consumer]: https://github.com/meltwater/gen_rmq/blob/master/documentation/examples/consumer.ex\n[example_publisher]: https://github.com/meltwater/gen_rmq/blob/master/documentation/examples/publisher.ex\n[example_processor]: https://github.com/meltwater/gen_rmq/blob/master/documentation/examples/processor.ex\n[example_rabbit_case]: https://github.com/meltwater/gen_rmq/blob/master/test/gen_rmq_publisher_test.exs\n[guide_consumer_basic_setup]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/basic_setup.md\n[guide_consumer_with_custom_deadletter_configuration]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/with_custom_deadletter_configuration.md\n[guide_consumer_with_custom_exchange_type]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/with_custom_exchange_type.md\n[guide_consumer_with_custom_queue_configuration]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/with_custom_queue_configuration.md\n[without_deadletter_configuration]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/without_deadletter_configuration.md\n[with_quorum_queue_type]: https://github.com/meltwater/gen_rmq/blob/master/documentation/guides/consumer/with_quorum_queue_type.md\n[consumer_telemetry_events]: https://github.com/meltwater/gen_rmq/blob/master/lib/gen_rmq/consumer/telemetry.ex\n[publisher_telemetry_events]: https://github.com/meltwater/gen_rmq/blob/master/lib/gen_rmq/publisher/telemetry.ex\n[trusted_commiters]: https://github.com/meltwater/gen_rmq/blob/master/TRUSTED-COMMITTERS.md\n[code_owners]: https://github.com/meltwater/gen_rmq/blob/master/.github/CODEOWNERS\n[license]: https://github.com/meltwater/gen_rmq/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeltwater%2Fgen_rmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeltwater%2Fgen_rmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeltwater%2Fgen_rmq/lists"}