{"id":20080689,"url":"https://github.com/cloud8421/rbt","last_synced_at":"2025-06-10T21:32:53.626Z","repository":{"id":139444204,"uuid":"139333927","full_name":"cloud8421/rbt","owner":"cloud8421","description":"Opinionated, high level RabbitMQ client wrapper","archived":false,"fork":false,"pushed_at":"2018-10-05T08:58:16.000Z","size":171,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T13:26:25.534Z","etag":null,"topics":["amqp","background-processing","elixir","elixir-lang","job-processor","rabbitmq","rabbitmq-client","rabbitmq-consumer"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"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/cloud8421.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-01T14:02:56.000Z","updated_at":"2018-10-05T08:58:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"6dfceee2-0f6e-42ba-9424-50c3ff9372c9","html_url":"https://github.com/cloud8421/rbt","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud8421%2Frbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud8421%2Frbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud8421%2Frbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud8421%2Frbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud8421","download_url":"https://codeload.github.com/cloud8421/rbt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud8421%2Frbt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259154524,"owners_count":22813622,"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":["amqp","background-processing","elixir","elixir-lang","job-processor","rabbitmq","rabbitmq-client","rabbitmq-consumer"],"created_at":"2024-11-13T15:29:38.964Z","updated_at":"2025-06-10T21:32:53.581Z","avatar_url":"https://github.com/cloud8421.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rbt\n\n[![Build Status](https://travis-ci.org/cloud8421/rbt.svg?branch=master)](https://travis-ci.org/cloud8421/rbt)\n[![Coverage Status](https://coveralls.io/repos/github/cloud8421/rbt/badge.svg?branch=master)](https://coveralls.io/github/cloud8421/rbt?branch=master)\n\nALPHA stage, usable with some extra care.\n\n## Guidelines\n\n- Opt-in, self-configuring topology\n- Small, explicit and composable building blocks\n- Configuration only for compile-time variables (e.g. which JSON decoder to use)\n- Always pass down configuration from the top, e.g. application -\u003e supervisor -\u003e single worker\n- Always pass options explicitly at start\n- Instrumentable\n- Smallest possible dependency surface (make as many as possible optional)\n- Support multiple mimetypes\n- Don't hide APIs, rather provide ways to compose them\n- Introspection to see running components at any given time\n\n## Features\n\n- [x] Consumers\n  - [x] auto retries with backoff\n  - [x] forward failures to separate exchange for capture\n  - [x] parallelized, bounded message handling\n  - [x] instrumentation hooks\n  - [x] manual consume/cancel control\n  - [x] multiple content types (erlang, json)\n- [x] Producers\n  - [x] internal buffering in case of disconnection\n  - [x] auto-fingerprint of published messages with generated uuid\n  - [x] instrumentation hooks\n  - [x] multiple content types (erlang, json)\n  - [x] test helpers\n- [x] RPC server\n- [x] RPC client\n- [x] Runtime topology information\n- [ ] Complete docs\n  - [x] Installation and configuration\n  - [x] Basic supervision tree setup\n  - [ ] Content types\n  - [ ] Working with consumers\n  - [ ] Working with producers\n  - [ ] Permanent failure handling\n  - [ ] Manual consume/cancel\n  - [x] Testing a consumer\n  - [ ] Testing a producer\n  - [ ] Instrumentation\n  - [ ] Correlation IDs\n  - [ ] Custom topologies\n  - [ ] Manage bindings\n  - [ ] RPC servers\n  - [ ] RPC clients\n\n## Installation\n\nThe package can be installed by adding `rbt` to your list of dependencies in `mix.exs` with the custom github url:\n\n```elixir\ndef deps do\n  [\n    {:rbt, github: \"cloud8421/rbt\", tag: \"v0.3.0\"},\n    {:jason, \"~\u003e 1.1\"}, # optional, but needed to support json-encoded messages\n  ]\nend\n```\n\n## Global configuration\n\nAs one of the goals of the library is remove hidden configuration as much as possible, it only supports a limited set of options that\ninfluence compilation. For example:\n\n```elixir\n  config :rbt,\n    json_adapter: Jason # default, can be omitted\n```\n\nOptions:\n  - `json_adapter` (defaults to `Jason`): which adapter to use to encode and decode json data. See the docs for `Rbt.Data` for more details,\n  but in general the adapter has to expose `decode/1` and `encode/1` functions. In both instances, the expected return values are either `{:ok, result}` or `{:error, reason}`. \n\n## Usage\n\nRBT components can be composed via supervision trees. Here's a fairly extended example that starts two connections (one for consumers, one for producers), a producer and a consumer.\n\n```elixir\ndefmodule ExampleSupervisor do\n  use Supervisor\n\n  def start_link(vhost_url) do\n    Supervisor.start_link(__MODULE__, vhost_url)\n  end\n\n  def init(opts) do\n    vhost_url = Keyword.fetch!(opts, :vhost_url)\n\n    children = [\n      {Rbt.Conn, uri: vhost_url, name: :prod_conn},\n      {Rbt.Conn, uri: vhost_url, name: :cons_conn},\n      {Rbt.Producer, \n       conn_ref: :prod_conn,\n       definitions: %{exchange_name: \"test-exchange\"},\n       create_infrastructure: true},\n      {Rbt.Consumer,\n       conn_ref: :cons_conn,\n       handler: MyHandler,\n       definitions: %{\n         exchange_name: \"test-exchange\",\n         queue_name: \"test-queue\",\n         routing_keys: [\"test.topic\"]\n       },\n       create_infrastructure: true,\n       max_retries: 3}\n    ]\n\n    Supervisor.init(children, strategy: :one_for_one)\n  end\nend\n```\n\nThe supervisor itself can be mounted inside the main application tree by adding `{ExampleSupervisor, vhost_url: \"amqp://\"}`.\n\nThe consumer worker references a `MyHandler` module which needs to implement the `Rbt.Consumer.Handler` behaviour:\n\n```elixir\ndefmodule MyHandler do\n  use Rbt.Consumer.Handler\n\n  def handle_event(event, meta) do\n    IO.inspect(event)\n    IO.inspect(meta)\n    :ok\n  end\nend\n```\n\nTo publish a message, it's possible to call:\n\n```elixir\nRbt.Producer.publish(\"test-exchange\", \"test.topic\", %{some: \"data\"}, message_id: \"my-client-id\")\n```\n\n## Testable components\n\nHere's some strategies to write testable components based on Rbt.\n\n### Consumer handlers\n\nAs a handler needs to implement a `handle_event/2` function, it's possible to make it easier to test by implementing a `handle_event/3` function (not a callback) which provides a third argument with defaults used for dependency injection.\n\nFor example:\n\n```elixir\ndefmodule MyHandlerWhichRepublishes do\n  use Rbt.Consumer.Handler\n\n  @default_context %{\n    producer: Rbt.Producer\n  }\n\n  def handle_event(event, meta, context \\\\ @default_context) do\n    # do some work\n    context.producer.publish(\"new-exchange\", \"new-topic\", %{some: \"new data\"})\n  end\nend\n```\n\nIn the snippet above, we provide a context map with a `producer` key, which is the module we want to use to produce new events. In our implementation\ncode, this module will use `Rbt.Producer`.\n\nWhen we test this function, we can override it with `Rbt.Producer.Sandbox`:\n\n```elixir\ntest_context = %{producer: Rbt.Producer.Sandbox}\nassert :ok == MyHandlerWhichRepublishes.handle_event(%{some: \"data\"}, %{}, test_context)\nassert 1 == Rbt.Producer.Sandbox.count_by_exchange(\"new-exchange\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud8421%2Frbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud8421%2Frbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud8421%2Frbt/lists"}