{"id":13778291,"url":"https://github.com/broadlume/hanami-events-cloud_pubsub","last_synced_at":"2025-07-13T18:10:49.452Z","repository":{"id":40234911,"uuid":"136084943","full_name":"broadlume/hanami-events-cloud_pubsub","owner":"broadlume","description":"A hanami-events adapter for Google Cloud Pub/Sub","archived":false,"fork":false,"pushed_at":"2022-07-06T20:02:13.000Z","size":293,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-01T12:19:11.139Z","etag":null,"topics":["google-cloud-pubsub","hanami","pubsub","ruby"],"latest_commit_sha":null,"homepage":"https://tryadhawk.com/jobs","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/broadlume.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-04T21:29:55.000Z","updated_at":"2022-07-06T17:03:20.000Z","dependencies_parsed_at":"2022-08-20T10:11:18.210Z","dependency_job_id":null,"html_url":"https://github.com/broadlume/hanami-events-cloud_pubsub","commit_stats":null,"previous_names":["adhawk/hanami-events-cloud_pubsub"],"tags_count":58,"template":false,"template_full_name":null,"purl":"pkg:github/broadlume/hanami-events-cloud_pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broadlume%2Fhanami-events-cloud_pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broadlume%2Fhanami-events-cloud_pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broadlume%2Fhanami-events-cloud_pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broadlume%2Fhanami-events-cloud_pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/broadlume","download_url":"https://codeload.github.com/broadlume/hanami-events-cloud_pubsub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broadlume%2Fhanami-events-cloud_pubsub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265183057,"owners_count":23723955,"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":["google-cloud-pubsub","hanami","pubsub","ruby"],"created_at":"2024-08-03T18:00:52.747Z","updated_at":"2025-07-13T18:10:49.408Z","avatar_url":"https://github.com/broadlume.png","language":"Ruby","funding_links":[],"categories":["Hanami Gem List"],"sub_categories":["Events"],"readme":"# Hanami Events for Google Cloud Pub/sub\n[![Build Status](https://travis-ci.org/adHawk/hanami-events-cloud_pubsub.svg?branch=master)](https://travis-ci.org/adHawk/hanami-events-cloud_pubsub) [![Maintainability](https://api.codeclimate.com/v1/badges/7341f70d4ed1d0bd7a5d/maintainability)](https://codeclimate.com/github/adHawk/hanami-events-cloud_pubsub/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/7341f70d4ed1d0bd7a5d/test_coverage)](https://codeclimate.com/github/adHawk/hanami-events-cloud_pubsub/test_coverage)\n\n## Installation\n\n```ruby\nbundle add hanami-events-cloud_pubsub\n```\n\nIf using Hanami, register the adapter in your `config/environment.rb`:\n\n```ruby\n# config/environment.rb\n# ...\nrequire_relative './../lib/my_app'\nrequire_relative './../apps/web/application'\n# ...\n\nrequire 'hanami/events/cloud_pubsub/register' # \u003c----\n```\n\nConfigure the pubsub adapter how you want (optional):\n\n```ruby\n# config/environment.rb\n\nHanami.configure do\n  environment :development do\n    cloud_pubsub do |config|\n      config.pubsub = { project_id: 'emulator' } # optional\n      config.logger = Hanami.logger # optional\n      config.namespace = :staging # optional\n      config.auto_create_topics = false # optional\n      config.auto_create_subscriptions = false # optional\n      config.on_shutdown = -\u003e(adapter) { Analytics.flush } # optional\n      config.error_handlers \u003c\u003c -\u003e(err, message) { MyErrorReporter.report(err) }\n      # ...\n    end\n  end\nend\n```\n\n## Usage\n\nThis gem is compatible with the\n[hanami-events](https://github.com/hanami/events) gem, with a couple caveats:\n\n1. All subscribers must specify an `id:` attribute. When you subscribe, you\nshould pass this:\n\n```ruby\nHanami.events.subscribe('user.deleted', id: 'my-subscriber-id') do |payload|\n  puts \"Deleted user: #{payload}\"\nend\n```\n\nAdditional options will be passed to `Google::Cloud::Pubsub::Subscription#listen`:\n```ruby\nHanami.events.subscribe('foo', id: 'bar', deadline: 30) do |payload|\n  sleep 29 # message will finish before deadline\nend\n```\n\n2. Responding to events is done in a different process via the CLI.\n\nFirst, create a config file:\n\n```ruby\n# config/cloudpubsub.rb\n\nrequire 'config/environment'\n\nHanami.boot\n\nclass CustomMiddleware\n  def call(message)\n    puts 'Middleware started!'\n    yield\n    puts 'Middleware ended!'\n  end\nend\n\nHanami::Events::CloudPubsub.configure do |config|\n  # required\n  config.subscriptions_loader = -\u003e do\n    # Ensure these files are not loaded until *after* the subscriptions are\n    # setup, or else you will have an undefined reference to `$events`\n    Hanami::Utils.require! 'apps/web/subscriptions'\n  end\n\n  # (optional)\n  config.logger = Hanami.logger\n\n  # (optional)\n  config.error_handlers \u003c\u003c lambda do |err, message|\n    Honeybadger.notify(err, context: message.attributes)\n  end\n\n  config.middleware \u003c\u003c CustomMiddleware.new # must respond to #call\nend\n```\n\nThen, run the worker process:\n\n```sh\nbundle exec cloudpubsub run\n```\n\n# `RequestId` Integration\n\nTo gem has an integration with [request_id](https://github.com/remind101/request_id), so you can trace interactions between various components in your app. To make it work properly, make sure the `request_id` is added to your Gemfile, then require the middleware:\n\n```ruby\nrequire 'hanami/events/cloud_pubsub/middleware/request_id'\n\nHanami::Events::CloudPubsub.configure do |config|\n  # ...\nend\n```\n\n\n# Yabeda Prometheus Integration\n\nIf you have the `yabeda-prometheus` gem installed, a `/metrics` endpoint will\nbe available on the health check server which can be scraped.\n\nAll you need to do to activate this is to make sure to `require 'yabeda/prometheus'`.\n\n# Testing\n\nIf you would like to use an emulator process for testing:\n\n```sh\n$(gcloud beta emulators pubsub env-init)\ngcloud beta emulators pubsub start\nbundle exec cloudpubsub run --emulator\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake spec` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/ianks/hanami-events-cloud_pubsub. This project is intended\nto be a safe, welcoming space for collaboration, and contributors are expected\nto adhere to the [Contributor Covenant](http://contributor-covenant.org) code\nof conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Hanami::Events::CloudPubsub project’s codebases,\nissue trackers, chat rooms and mailing lists is expected to follow the [code of\nconduct](https://github.com/ianks/hanami-events-cloud_pubsub/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroadlume%2Fhanami-events-cloud_pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbroadlume%2Fhanami-events-cloud_pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroadlume%2Fhanami-events-cloud_pubsub/lists"}