trabox 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +150 -16
  3. data/Rakefile +48 -2
  4. data/lib/trabox/version.rb +1 -1
  5. metadata +17 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dfd087c02a6876a14092f0c4a98a1d3769ddfd07311a19fb144d631f0ef23ac
4
- data.tar.gz: f2f76599e4c55ee53db897dbf024af024b2edb5d9ee45f37518be50b12f92d67
3
+ metadata.gz: e7d6e1156090efc8e33e9618f6f449dc7363d67e58aff81324dc7300ab4d644a
4
+ data.tar.gz: b898fedf626581cee69767ea4f2a810e3fc242e6a6d955d6c0f284ace31d779c
5
5
  SHA512:
6
- metadata.gz: af18284f3f67a580d69d03d17027113435bbd323e948d26d73d3f58ace23494a10f495abbff0b87af535cc551b7d2f6c756e1d614721d25007791afd3bb058d9
7
- data.tar.gz: 93a506e52fc94ad7f075c05416997e74ae3a3315da95b21175676c1c81b0488c736893a7066deb367aeb0b2a1cc5fe6f6730141a5bb098be23ecb2139255572d
6
+ metadata.gz: e22b0f8227e22ac12f5605671ffbd030e9fbc1bf30b38c38194e2f8e6936b8dc6844b09078ea7e3c648e265d0b04c7f0faeb5636765a5f66515d9dbf11b29eb3
7
+ data.tar.gz: b47485d03057b4781b4dafd4fd9cf6668814ee58141c253f5b206a7402027cf925d0e676bc2c17e0c8d817c8878ef8516a548f724a217d231bb5abd34dbd1d48
data/README.md CHANGED
@@ -1,59 +1,193 @@
1
1
  # Trabox
2
2
 
3
- [日本語](README.ja.md)
3
+ \[[Japanese](README.ja.md)]\[[English](README.md)]
4
4
 
5
5
  Transactional-Outbox for Rails.
6
6
 
7
+ ![](./docs/images/architecture.jpg)
8
+
9
+ ## Features
10
+
11
+ - Publishing event data in transactional-outbox pattern
12
+ - Polling multiple databases and outbox tables
13
+ - Can use your own publisher/subscriber
14
+ - Custom Metrics with dogstatsd
15
+ - Ensure message ordering
16
+
7
17
  **Supported publisher**
8
18
 
9
19
  - Google Cloud Pub/Sub
10
20
 
21
+ ## Requirements
22
+
23
+ - Ruby 2.6+
24
+ - Rails 6.0+
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```ruby
31
+ gem 'trabox'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```bash
37
+ bundle install
38
+ bin/rails g trabox:configure
39
+ ```
40
+
41
+ This will generate config file `config/initializers/trabox.rb`.
42
+
43
+ **Optional**:
44
+
45
+ ```bash
46
+ bundle binstubs trabox
47
+ ```
48
+
11
49
  ## Usage
12
50
 
13
- ### Create outbox tables
51
+ ### Generate outbox tables
14
52
 
15
53
  ```bash
54
+ # generate model
16
55
  bin/rails g trabox:model <NAME>
56
+
57
+ # Help
58
+ bin/rails g trabox:model --help
59
+ Usage:
60
+ rails generate trabox:model NAME [field[:type][:index] field[:type][:index]] [options]
61
+ ...
62
+ ```
63
+
64
+ **additional option: --polymorphic=\<NAME>**
65
+ This option is inserted references column in generated outbox model.
66
+ This use to associate event record with outbox record when the application is designed immutable data model.
67
+
68
+ example:`bin/rails g trabox:model event --polymorphic=event`
69
+
70
+ ```ruby
71
+ class CreateEvents < ActiveRecord::Migration[6.1]
72
+ def change
73
+ create_table :events do |t|
74
+ t.references :event, polymorphic: true, null: false # additional column
75
+ t.binary :event_data
76
+ t.string :message_id
77
+ t.datetime :published_at
78
+
79
+ t.timestamps
80
+ end
81
+ end
82
+ end
83
+ ```
84
+
85
+ ### Registering event data
86
+
87
+ Insert events to publish into the generated outbox table as part of the local transaction.
88
+
89
+ ```ruby
90
+ # Your rails application
91
+ ActiveRecord::Base.transaction do
92
+ user = User.create! name: 'hoge'
93
+
94
+ Event.create! event_data: <serialized_user_event>
95
+ end
17
96
  ```
18
97
 
19
- ### Run
98
+ ### Running relayer
20
99
 
21
100
  ```bash
22
101
  bin/trabox relay
102
+
103
+ # Help
104
+ bin/trabox relay -h
105
+ Usage: trabox relay [OPTIONS]
106
+
107
+ Overwrite configuration
108
+
109
+ -l, --limit NUM
110
+ -i, --interval SEC
111
+ -L, --[no-]lock
112
+ --log-level LEVEL
113
+
114
+
23
115
  ```
24
116
 
117
+ ### Running subscriber
118
+
25
119
  ```bash
26
120
  bin/trabox subscribe
121
+
122
+ # Help
123
+ bin/trabox subscribe -h
124
+ Usage: trabox subscribe [OPTIONS]
125
+
126
+ Overwrite configuration
127
+
128
+ --log-level LEVEL
27
129
  ```
28
130
 
29
- How to use my plugin.
131
+ ## Metrics
30
132
 
31
- ## Installation
133
+ The default namespace of metrics is `trabox`.
134
+ The namespace can be changed with `TRABOX_METRIC_NAMESPACE` environment variable.
32
135
 
33
- Add this line to your application's Gemfile:
136
+ | name | description |
137
+ | ------------------------------- | -------------------------------------------- |
138
+ | unpublished_event_count | Number of events that will be published |
139
+ | published_event_count | Number of published events |
140
+ | find_events_error_count | Number of errors that find events to publish |
141
+ | publish_event_error_count | Number of publication errors |
142
+ | update_event_record_error_count | Number of record update errors |
34
143
 
35
- ```ruby
36
- gem 'trabox'
37
- ```
144
+ ### Health check
38
145
 
39
- And then execute:
146
+ | command | metric name |
147
+ | --------- | ----------------------- |
148
+ | relay | relay.service.check |
149
+ | subscribe | subscribe.service.check |
150
+
151
+ ## Sequence diagram
152
+
153
+ ![](./docs/images/sequence-diagram.svg)
154
+
155
+ ## Contributing
156
+
157
+ Bug reports and pull requests are welcome.
158
+
159
+ ## Development
160
+
161
+ ### Install gems
40
162
 
41
163
  ```bash
42
164
  bundle install
43
- bin/rails g trabox:configure
44
165
  ```
45
166
 
46
- This will generate config file `config/initializers/trabox.rb`.
167
+ ### Start mysql / pubsub emulator
47
168
 
48
- **Optional**:
169
+ ```bash
170
+ docker-compose up
171
+ ```
172
+
173
+ **setup db**
49
174
 
50
175
  ```bash
51
- bundle binstubs trabox
176
+ cd spec/rails_app
177
+ bin/rails db:setup
52
178
  ```
53
179
 
54
- ## Contributing
180
+ **create topic / subscribe**
55
181
 
56
- Contribution directions go here.
182
+ ```bash
183
+ rake trabox:pubsub_setup
184
+ ```
185
+
186
+ ### Test
187
+
188
+ ```bash
189
+ bin/rspec
190
+ ```
57
191
 
58
192
  ## License
59
193
 
data/Rakefile CHANGED
@@ -1,3 +1,49 @@
1
- require "bundler/setup"
1
+ require 'bundler/setup'
2
2
 
3
- require "bundler/gem_tasks"
3
+ require 'bundler/gem_tasks'
4
+
5
+ namespace :trabox do
6
+ desc 'create topic/subscribe'
7
+ task :pubsub_setup do
8
+ require 'google/cloud/pubsub'
9
+ require 'logger'
10
+
11
+ ENV['PUBSUB_EMULATOR_HOST'] ||= 'localhost:8085'
12
+ ENV['GOOGLE_CLOUD_PROJECT'] ||= 'trabox'
13
+
14
+ logger = Logger.new($stdout)
15
+
16
+ topic_id = ENV['PUBSUB_TOPIC_ID'] || 'trabox'
17
+ subscription_id = ENV['PUBSUB_SUBSCRIPTION_ID'] || 'trabox-sub'
18
+
19
+ pubsub = Google::Cloud::Pubsub.new
20
+
21
+ ##################
22
+ # create topic #
23
+ ##################
24
+
25
+ logger.info 'Create Topic'
26
+
27
+ topic = pubsub.topic topic_id
28
+
29
+ topic&.delete
30
+
31
+ topic = pubsub.create_topic topic_id
32
+
33
+ puts "Topic #{topic.name} created."
34
+
35
+ #########################
36
+ # create subscription #
37
+ #########################
38
+
39
+ logger.info 'Create Subscription'
40
+
41
+ subscription = topic.subscription subscription_id
42
+
43
+ subscription&.delete
44
+
45
+ topic.subscribe subscription_id, message_ordering: true
46
+
47
+ puts "Pull subscription #{subscription_id} created with message ordering."
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trabox
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kosay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-08 00:00:00.000000000 Z
11
+ date: 2025-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogstatsd-ruby
@@ -82,9 +82,6 @@ dependencies:
82
82
  name: rails
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '6.0'
88
85
  - - ">="
89
86
  - !ruby/object:Gem::Version
90
87
  version: 6.0.0
@@ -92,12 +89,23 @@ dependencies:
92
89
  prerelease: false
93
90
  version_requirements: !ruby/object:Gem::Requirement
94
91
  requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '6.0'
98
92
  - - ">="
99
93
  - !ruby/object:Gem::Version
100
94
  version: 6.0.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: appraisal
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.5'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.5'
101
109
  description: Transactional-Outbox for Rails
102
110
  email:
103
111
  - ekr59uv25@gmail.com
@@ -157,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
165
  - !ruby/object:Gem::Version
158
166
  version: '0'
159
167
  requirements: []
160
- rubygems_version: 3.3.7
168
+ rubygems_version: 3.1.6
161
169
  signing_key:
162
170
  specification_version: 4
163
171
  summary: Transactional-Outbox for Rails