{"id":13877912,"url":"https://github.com/sarub0b0/trabox","last_synced_at":"2025-12-26T23:46:24.360Z","repository":{"id":65540876,"uuid":"565495012","full_name":"sarub0b0/trabox","owner":"sarub0b0","description":"Transactional outbox pattern for Rails","archived":false,"fork":false,"pushed_at":"2024-11-22T02:15:15.000Z","size":468,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-22T03:20:03.014Z","etag":null,"topics":["microservice","rails","trabox","transactional-outbox"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/trabox","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/sarub0b0.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"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":"2022-11-13T15:38:54.000Z","updated_at":"2024-11-21T21:34:05.000Z","dependencies_parsed_at":"2023-10-24T10:27:37.239Z","dependency_job_id":"98aae8a0-397c-4069-83bc-27db3653493d","html_url":"https://github.com/sarub0b0/trabox","commit_stats":{"total_commits":161,"total_committers":3,"mean_commits":"53.666666666666664","dds":0.3416149068322981,"last_synced_commit":"fd69964004205329317c0945c2c6cc1b51ec3828"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarub0b0%2Ftrabox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarub0b0%2Ftrabox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarub0b0%2Ftrabox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sarub0b0%2Ftrabox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sarub0b0","download_url":"https://codeload.github.com/sarub0b0/trabox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226134226,"owners_count":17578778,"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":["microservice","rails","trabox","transactional-outbox"],"created_at":"2024-08-06T08:01:34.706Z","updated_at":"2025-12-26T23:46:24.331Z","avatar_url":"https://github.com/sarub0b0.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Trabox\n\n\\[[Japanese](README.ja.md)]\\[[English](README.md)]\n\nTransactional-Outbox for Rails.\n\n![](./docs/images/architecture.jpg)\n\n## 機能\n\n- Transactional-Outbox パターンでのイベントデータ公開\n- 複数のデータベース・Outbox テーブルに対応\n- `publish/subscribe`メソッドをもつ自作の publisher/subscriber を使用可能\n- dogstatsd ベースのメトリクス\n- 受信するメッセージの順序を維持する\n\n**サポートしている publisher**\n\n- Google Cloud Pub/Sub\n\n## 必要条件\n\n- Ruby 2.6+\n- Rails 6.0+\n\n## インストール\n\n`Gemfile`に下記を追記\n\n```ruby\ngem 'trabox'\n```\n\n下記コマンドを実行\n\n```bash\nbundle install\nbin/rails g trabox:configure\n```\n\nこれで、`config/initializers/trabox.rb`ファイルが生成されます。\n\n**オプション**\n\n```bash\nbundle binstubs trabox\n```\n\n## 使い方\n\n### outbox テーブルの作成\n\n下記コマンドで outbox モデルのファイルが作成されます。  \n`bin/rails g model`のオプションを使えるので、必要に応じて変更してください。\n\n```bash\n# generate model\nbin/rails g trabox:model \u003cNAME\u003e\n\n# Help\n$ bin/rails g trabox:model --help\nUsage:\n  rails generate trabox:model NAME [field[:type][:index] field[:type][:index]] [options]\n...\n```\n\n**追加のオプション: --polymorphic=\\\u003cNAME\u003e** オプションをつけると`references`カラムが追加されます。  \nこのオプションはイミュータブルデータモデルに基づいた設計のときにイベントデータと outbox データを関連づけるのに使用します。\n\n例：`bin/rails g trabox:model event --polymorphic=event`\n\n```ruby\nclass CreateEvents \u003c ActiveRecord::Migration[6.1]\n  def change\n    create_table :events do |t|\n      t.references :event, polymorphic: true, null: false # --polymorphicオプションで生成されたカラム\n      t.binary :event_data\n      t.string :message_id\n      t.datetime :published_at\n\n      t.timestamps\n    end\n  end\nend\n```\n\n### Event データの登録\n\nPublish するイベントデータを作成した outbox テーブルに登録します。\n\n```ruby\n# Your rails application\nActiveRecord::Base.transaction do\n  user = User.create! name: 'hoge'\n\n  Event.create! event_data: \u003cserialized_user_event\u003e\nend\n```\n\n### Relayer 実行\n\n```bash\nbin/trabox relay\n\n# Help\nbin/trabox relay -h\nUsage: trabox relay [OPTIONS]\n\nOverwrite configuration\n\n    -l, --limit NUM\n    -i, --interval SEC\n    -L, --[no-]lock\n        --log-level LEVEL\n\n```\n\n#### Subscriber 実行\n\n```bash\nbin/trabox subscribe\n\n# Help\n bin/trabox subscribe -h\nUsage: trabox subscribe [OPTIONS]\n\nOverwrite configuration\n\n        --log-level LEVEL\n```\n\n## メトリクス\n\nメトリクスの名前空間の初期値は`trabox`です。  \n名前空間は`TRABOX_METRIC_NAMESPACE`環境変数で変更可能です。\n\n| 名前                            | 説明                                             |\n| ------------------------------- | ------------------------------------------------ |\n| unpublished_event_count         | パブリッシュするイベント数                       |\n| published_event_count           | パブリッシュしたイベント数                       |\n| find_events_error_count         | パブリッシュするイベントの取得に失敗した数       |\n| publish_event_error_count       | イベントのパブリッシュに失敗した数               |\n| update_event_record_error_count | パブリッシュしたイベントのカラム更新に失敗した数 |\n\n### Health check\n\n| command   | metric name             |\n| --------- | ----------------------- |\n| relay     | relay.service.check     |\n| subscribe | subscribe.service.check |\n\n## Sequence diagram\n\n![](./docs/images/sequence-diagram.svg)\n\n## Contributing\n\nBug reports and pull requests are welcome.\n\n## Development\n\n### Install gems\n\n```bash\nbundle install\n```\n\n### Start mysql / pubsub emulator\n\n```bash\ndocker-compose up\n```\n\n**setup db**\n\n```bash\ncd spec/rails_app\nbin/rails db:setup\n```\n\n**create topic / subscribe**\n\n```bash\nrake trabox:pubsub_setup\n```\n\n### Test\n\n```bash\nbin/rspec\n```\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsarub0b0%2Ftrabox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsarub0b0%2Ftrabox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsarub0b0%2Ftrabox/lists"}