{"id":16777894,"url":"https://github.com/mschae/intermediary","last_synced_at":"2025-03-16T19:19:11.617Z","repository":{"id":19369879,"uuid":"22610095","full_name":"mschae/intermediary","owner":"mschae","description":"This gem is responsible for emitting and receiving updates to changes that occur within an app.","archived":false,"fork":false,"pushed_at":"2014-09-30T13:58:07.000Z","size":177,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-23T05:44:45.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/mschae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-04T15:49:42.000Z","updated_at":"2015-02-23T21:57:26.000Z","dependencies_parsed_at":"2022-09-03T04:42:12.625Z","dependency_job_id":null,"html_url":"https://github.com/mschae/intermediary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschae%2Fintermediary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschae%2Fintermediary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschae%2Fintermediary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschae%2Fintermediary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mschae","download_url":"https://codeload.github.com/mschae/intermediary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243918631,"owners_count":20368745,"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":[],"created_at":"2024-10-13T07:26:11.805Z","updated_at":"2025-03-16T19:19:11.600Z","avatar_url":"https://github.com/mschae.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intermediary\n\nThis gems aims to unify asynchronous communication between different apps in a\nSOA.\n\nIt is built on top of the awesome bunny gem, which provides an interface to\nRabbitMQ.\n\nThe emitter (the app that publishes updates) in this gem does not know who\nconsumes those updates. To this end a topic exchange is being used. To make\nsubscribing to updates as straightforward as possible the exchange key mimics\nrestful routes. Updates to resources are published in an exchange key that\nreflects the resource's href (down to the host).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'intermediary'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install intermediary\n\n## Usage\n\nAs explained above, gem provides two elements to exchange updates between apps:\n- The emitter\n- The listener\n\n### The Emitter\n\nTo use the emitter one simply inherits from `Intermediary::Emitters::Base` as\nfollows:\n\n```ruby\nclass MyEmitter \u003c Intermediary::Emitters::Base\n  def href\n    # Some fance href generation...\n  end\nend\n```\n\nPer default the initializer takes one argument (the object). As everything else\nit can be customized by overwriting it.\n\nThe href method always has to be supplied to indicate how to construct the\nrouting key.\n\nPer default the payload emitted is the the object's `.attributes` and the\nevent.\n\n### The Listener\n\nThe receiver is merely a user-defined class that implements the following\nmethod: `self.act`. Which takes three arguments: `payload`, `routing_key` and\n`properties`. The `payload` will be a hash.\n\nFurthermore the class has to define `@queue_name` and `@routing_key`.\n\nExample:\n```ruby\nclass MyListener\n  @queue_name  = \"my-awesome-queue\"\n  @routing_key = \"app_example_com.model.#\"\n\n  def self.act(payload, routing_key, properties)\n    puts payload.inspect\n  end\nend\n```\n\n**Please note that multiple receivers with the same queue name will share\nitems!**\n\nTo register a listener, please call the following (e.g. in an initializer):\n\n```ruby\nIntermediary::Listeners.register MyListener\n```\n\nAdditionally one can define a `self.on_error` method with takes one argument:\nThe error itself. It will get called when processing a job failed. Feel free\nto pass it to your favorite error tracker.\n\n**Pro tip**\n\nIf you want to share the same `on_error` handler amongst multiple listeners,\nhow about using a module, eh?\n\n## Contributing\n\n1. Fork it ( http://github.com/\u003cmy-github-username\u003e/intermediary/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschae%2Fintermediary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmschae%2Fintermediary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschae%2Fintermediary/lists"}