trabox 0.1.2 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dfd087c02a6876a14092f0c4a98a1d3769ddfd07311a19fb144d631f0ef23ac
4
- data.tar.gz: f2f76599e4c55ee53db897dbf024af024b2edb5d9ee45f37518be50b12f92d67
3
+ metadata.gz: 10134c8640681cb8e318e0eae8c0d2e5bb9a2b35a820ab2f753a48718baa773f
4
+ data.tar.gz: c4d99b320e40138b12af2fa0773548ef0b2b835533e1a6c8bd95f6218203f9bf
5
5
  SHA512:
6
- metadata.gz: af18284f3f67a580d69d03d17027113435bbd323e948d26d73d3f58ace23494a10f495abbff0b87af535cc551b7d2f6c756e1d614721d25007791afd3bb058d9
7
- data.tar.gz: 93a506e52fc94ad7f075c05416997e74ae3a3315da95b21175676c1c81b0488c736893a7066deb367aeb0b2a1cc5fe6f6730141a5bb098be23ecb2139255572d
6
+ metadata.gz: 48ef456ee8180a84c31143dce056ec3dbda8eafd855b3ff46c5248a95d7d838c3f71a797dc9267cd89693802588fd5edfc9b1deb08fc5e5a318f599efaf6eda3
7
+ data.tar.gz: 4b315ed9f8ebcde7105f56ed0449b3868dccf5c9d2ebe0076213a9cfb00f75d08896b9ded3e3c38d7f426fd994a5994aa2e2f9592296bc0ba077ccda661b3e8a
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 3.2+
24
+ - Rails 7.2+
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
@@ -38,7 +38,7 @@ module Trabox
38
38
  rescue StandardError => e
39
39
  Rails.logger.error e
40
40
 
41
- ActiveRecord::Base.clear_all_connections!
41
+ ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
42
42
 
43
43
  Metric.service_check('relay.service.check', Metric::SERVICE_CRITICAL)
44
44
  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.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kosay
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-12-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: dogstatsd-ruby
@@ -82,22 +81,30 @@ dependencies:
82
81
  name: rails
83
82
  requirement: !ruby/object:Gem::Requirement
84
83
  requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '6.0'
88
84
  - - ">="
89
85
  - !ruby/object:Gem::Version
90
- version: 6.0.0
86
+ version: 7.2.0
91
87
  type: :runtime
92
88
  prerelease: false
93
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 7.2.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: appraisal
96
+ requirement: !ruby/object:Gem::Requirement
94
97
  requirements:
95
98
  - - "~>"
96
99
  - !ruby/object:Gem::Version
97
- version: '6.0'
98
- - - ">="
100
+ version: '2.5'
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
99
106
  - !ruby/object:Gem::Version
100
- version: 6.0.0
107
+ version: '2.5'
101
108
  description: Transactional-Outbox for Rails
102
109
  email:
103
110
  - ekr59uv25@gmail.com
@@ -142,7 +149,6 @@ homepage: https://github.com/sarub0b0/trabox
142
149
  licenses:
143
150
  - MIT
144
151
  metadata: {}
145
- post_install_message:
146
152
  rdoc_options: []
147
153
  require_paths:
148
154
  - lib
@@ -150,15 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
156
  requirements:
151
157
  - - ">="
152
158
  - !ruby/object:Gem::Version
153
- version: '2.6'
159
+ version: '3.2'
154
160
  required_rubygems_version: !ruby/object:Gem::Requirement
155
161
  requirements:
156
162
  - - ">="
157
163
  - !ruby/object:Gem::Version
158
164
  version: '0'
159
165
  requirements: []
160
- rubygems_version: 3.3.7
161
- signing_key:
166
+ rubygems_version: 3.6.9
162
167
  specification_version: 4
163
168
  summary: Transactional-Outbox for Rails
164
169
  test_files: []