pub_sub_model_sync 0.1.2
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +220 -0
- data/LICENSE.txt +21 -0
- data/README.md +183 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pub_sub_model_sync.rb +20 -0
- data/lib/pub_sub_model_sync/config.rb +20 -0
- data/lib/pub_sub_model_sync/connector.rb +24 -0
- data/lib/pub_sub_model_sync/message_processor.rb +86 -0
- data/lib/pub_sub_model_sync/mock_google_service.rb +44 -0
- data/lib/pub_sub_model_sync/mock_rabbit_service.rb +48 -0
- data/lib/pub_sub_model_sync/publisher.rb +47 -0
- data/lib/pub_sub_model_sync/publisher_concern.rb +50 -0
- data/lib/pub_sub_model_sync/railtie.rb +13 -0
- data/lib/pub_sub_model_sync/runner.rb +40 -0
- data/lib/pub_sub_model_sync/service_google.rb +66 -0
- data/lib/pub_sub_model_sync/service_rabbit.rb +81 -0
- data/lib/pub_sub_model_sync/subscriber_concern.rb +42 -0
- data/lib/pub_sub_model_sync/tasks/worker.rake +8 -0
- data/lib/pub_sub_model_sync/version.rb +5 -0
- data/pub_sub_model_sync.gemspec +42 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2474d763e9b95cd2ddf83284ed095af1e1c8d53fe4ffc89fbe7249e8c198d38b
|
4
|
+
data.tar.gz: 87ab9ca1c4167ebf314c1bdbd48bd7216e7e1036acbbb2a6c93f82ddd7bb80e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a9ecb33cb7e85a76d797de1e390cf2a6a1086c245512695e46610cc18c1fa9273c821002177d30bc78ffe4159239733f287a665b69ded4f0d4490486072ff97
|
7
|
+
data.tar.gz: be9b8bf52ae416e9bf2667c3a6aa18cbbdc30aad265d71f00f1b90594a1f09d5a7498843e6f5361dd1562f151f0a7d73b7166bc4351fe02992a4dd1080ec587c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This is the configuration used to check the rubocop source code.
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- 'spec/spec_helper.rb'
|
6
|
+
- 'Gemfile'
|
7
|
+
- 'Rakefile'
|
8
|
+
- 'bin/*'
|
9
|
+
TargetRubyVersion: 2.3
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/**/*.rb'
|
14
|
+
|
15
|
+
|
16
|
+
Style/SymbolArray:
|
17
|
+
Exclude:
|
18
|
+
- 'Gemfile'
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/RescueStandardError:
|
24
|
+
EnforcedStyle: implicit
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.3.1
|
7
|
+
before_install: gem install bundler -v 2.0.2
|
8
|
+
|
9
|
+
script:
|
10
|
+
- bundle install
|
11
|
+
# disabled cause of: An error occurred while Style/PercentLiteralDelimiters cop
|
12
|
+
# - bundle exec rubocop
|
13
|
+
- bundle exec rspec
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at owenperedo@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pub_sub_model_sync (0.1.2)
|
5
|
+
activesupport
|
6
|
+
rails
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (5.2.4.1)
|
12
|
+
actionpack (= 5.2.4.1)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailer (5.2.4.1)
|
16
|
+
actionpack (= 5.2.4.1)
|
17
|
+
actionview (= 5.2.4.1)
|
18
|
+
activejob (= 5.2.4.1)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.2.4.1)
|
22
|
+
actionview (= 5.2.4.1)
|
23
|
+
activesupport (= 5.2.4.1)
|
24
|
+
rack (~> 2.0, >= 2.0.8)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.2.4.1)
|
29
|
+
activesupport (= 5.2.4.1)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.2.4.1)
|
35
|
+
activesupport (= 5.2.4.1)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.2.4.1)
|
38
|
+
activesupport (= 5.2.4.1)
|
39
|
+
activerecord (5.2.4.1)
|
40
|
+
activemodel (= 5.2.4.1)
|
41
|
+
activesupport (= 5.2.4.1)
|
42
|
+
arel (>= 9.0)
|
43
|
+
activestorage (5.2.4.1)
|
44
|
+
actionpack (= 5.2.4.1)
|
45
|
+
activerecord (= 5.2.4.1)
|
46
|
+
marcel (~> 0.3.1)
|
47
|
+
activesupport (5.2.4.1)
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
|
+
i18n (>= 0.7, < 2)
|
50
|
+
minitest (~> 5.1)
|
51
|
+
tzinfo (~> 1.1)
|
52
|
+
addressable (2.7.0)
|
53
|
+
public_suffix (>= 2.0.2, < 5.0)
|
54
|
+
amq-protocol (2.3.0)
|
55
|
+
arel (9.0.0)
|
56
|
+
ast (2.4.0)
|
57
|
+
builder (3.2.4)
|
58
|
+
bunny (2.14.3)
|
59
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
60
|
+
concurrent-ruby (1.1.6)
|
61
|
+
crass (1.0.6)
|
62
|
+
diff-lcs (1.3)
|
63
|
+
erubi (1.9.0)
|
64
|
+
faraday (0.17.3)
|
65
|
+
multipart-post (>= 1.2, < 3)
|
66
|
+
globalid (0.4.2)
|
67
|
+
activesupport (>= 4.2.0)
|
68
|
+
google-cloud-core (1.3.2)
|
69
|
+
google-cloud-env (~> 1.0)
|
70
|
+
google-cloud-env (1.2.1)
|
71
|
+
faraday (~> 0.11)
|
72
|
+
google-cloud-pubsub (1.0.2)
|
73
|
+
concurrent-ruby (~> 1.1)
|
74
|
+
google-cloud-core (~> 1.2)
|
75
|
+
google-gax (~> 1.7)
|
76
|
+
googleapis-common-protos (>= 1.3.9, < 2.0)
|
77
|
+
grpc-google-iam-v1 (~> 0.6.9)
|
78
|
+
google-gax (1.7.1)
|
79
|
+
google-protobuf (~> 3.2)
|
80
|
+
googleapis-common-protos (>= 1.3.5, < 2.0)
|
81
|
+
googleauth (>= 0.6.2, < 0.10.0)
|
82
|
+
grpc (>= 1.7.2, < 2.0)
|
83
|
+
rly (~> 0.2.3)
|
84
|
+
google-protobuf (3.11.4-universal-darwin)
|
85
|
+
googleapis-common-protos (1.3.9)
|
86
|
+
google-protobuf (~> 3.0)
|
87
|
+
googleapis-common-protos-types (~> 1.0)
|
88
|
+
grpc (~> 1.0)
|
89
|
+
googleapis-common-protos-types (1.0.4)
|
90
|
+
google-protobuf (~> 3.0)
|
91
|
+
googleauth (0.9.0)
|
92
|
+
faraday (~> 0.12)
|
93
|
+
jwt (>= 1.4, < 3.0)
|
94
|
+
memoist (~> 0.16)
|
95
|
+
multi_json (~> 1.11)
|
96
|
+
os (>= 0.9, < 2.0)
|
97
|
+
signet (~> 0.7)
|
98
|
+
grpc (1.27.0-universal-darwin)
|
99
|
+
google-protobuf (~> 3.11)
|
100
|
+
googleapis-common-protos-types (~> 1.0)
|
101
|
+
grpc-google-iam-v1 (0.6.9)
|
102
|
+
googleapis-common-protos (>= 1.3.1, < 2.0)
|
103
|
+
grpc (~> 1.0)
|
104
|
+
i18n (1.8.2)
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
jaro_winkler (1.5.4)
|
107
|
+
jwt (2.2.1)
|
108
|
+
loofah (2.4.0)
|
109
|
+
crass (~> 1.0.2)
|
110
|
+
nokogiri (>= 1.5.9)
|
111
|
+
mail (2.7.1)
|
112
|
+
mini_mime (>= 0.1.1)
|
113
|
+
marcel (0.3.3)
|
114
|
+
mimemagic (~> 0.3.2)
|
115
|
+
memoist (0.16.2)
|
116
|
+
method_source (0.9.2)
|
117
|
+
mimemagic (0.3.4)
|
118
|
+
mini_mime (1.0.2)
|
119
|
+
mini_portile2 (2.4.0)
|
120
|
+
minitest (5.14.0)
|
121
|
+
multi_json (1.14.1)
|
122
|
+
multipart-post (2.1.1)
|
123
|
+
nio4r (2.5.2)
|
124
|
+
nokogiri (1.10.9)
|
125
|
+
mini_portile2 (~> 2.4.0)
|
126
|
+
os (1.0.1)
|
127
|
+
parallel (1.19.1)
|
128
|
+
parser (2.7.0.4)
|
129
|
+
ast (~> 2.4.0)
|
130
|
+
public_suffix (4.0.3)
|
131
|
+
rack (2.2.2)
|
132
|
+
rack-test (1.1.0)
|
133
|
+
rack (>= 1.0, < 3)
|
134
|
+
rails (5.2.4.1)
|
135
|
+
actioncable (= 5.2.4.1)
|
136
|
+
actionmailer (= 5.2.4.1)
|
137
|
+
actionpack (= 5.2.4.1)
|
138
|
+
actionview (= 5.2.4.1)
|
139
|
+
activejob (= 5.2.4.1)
|
140
|
+
activemodel (= 5.2.4.1)
|
141
|
+
activerecord (= 5.2.4.1)
|
142
|
+
activestorage (= 5.2.4.1)
|
143
|
+
activesupport (= 5.2.4.1)
|
144
|
+
bundler (>= 1.3.0)
|
145
|
+
railties (= 5.2.4.1)
|
146
|
+
sprockets-rails (>= 2.0.0)
|
147
|
+
rails-dom-testing (2.0.3)
|
148
|
+
activesupport (>= 4.2.0)
|
149
|
+
nokogiri (>= 1.6)
|
150
|
+
rails-html-sanitizer (1.3.0)
|
151
|
+
loofah (~> 2.3)
|
152
|
+
railties (5.2.4.1)
|
153
|
+
actionpack (= 5.2.4.1)
|
154
|
+
activesupport (= 5.2.4.1)
|
155
|
+
method_source
|
156
|
+
rake (>= 0.8.7)
|
157
|
+
thor (>= 0.19.0, < 2.0)
|
158
|
+
rainbow (3.0.0)
|
159
|
+
rake (13.0.1)
|
160
|
+
rexml (3.2.4)
|
161
|
+
rly (0.2.3)
|
162
|
+
rspec (3.9.0)
|
163
|
+
rspec-core (~> 3.9.0)
|
164
|
+
rspec-expectations (~> 3.9.0)
|
165
|
+
rspec-mocks (~> 3.9.0)
|
166
|
+
rspec-core (3.9.1)
|
167
|
+
rspec-support (~> 3.9.1)
|
168
|
+
rspec-expectations (3.9.0)
|
169
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
170
|
+
rspec-support (~> 3.9.0)
|
171
|
+
rspec-mocks (3.9.1)
|
172
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
173
|
+
rspec-support (~> 3.9.0)
|
174
|
+
rspec-support (3.9.2)
|
175
|
+
rubocop (0.80.1)
|
176
|
+
jaro_winkler (~> 1.5.1)
|
177
|
+
parallel (~> 1.10)
|
178
|
+
parser (>= 2.7.0.1)
|
179
|
+
rainbow (>= 2.2.2, < 4.0)
|
180
|
+
rexml
|
181
|
+
ruby-progressbar (~> 1.7)
|
182
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
183
|
+
ruby-progressbar (1.10.1)
|
184
|
+
signet (0.11.0)
|
185
|
+
addressable (~> 2.3)
|
186
|
+
faraday (~> 0.9)
|
187
|
+
jwt (>= 1.5, < 3.0)
|
188
|
+
multi_json (~> 1.10)
|
189
|
+
sprockets (3.7.2)
|
190
|
+
concurrent-ruby (~> 1.0)
|
191
|
+
rack (> 1, < 3)
|
192
|
+
sprockets-rails (3.2.1)
|
193
|
+
actionpack (>= 4.0)
|
194
|
+
activesupport (>= 4.0)
|
195
|
+
sprockets (>= 3.0.0)
|
196
|
+
sqlite3 (1.4.2)
|
197
|
+
thor (1.0.1)
|
198
|
+
thread_safe (0.3.6)
|
199
|
+
tzinfo (1.2.6)
|
200
|
+
thread_safe (~> 0.1)
|
201
|
+
unicode-display_width (1.6.1)
|
202
|
+
websocket-driver (0.7.1)
|
203
|
+
websocket-extensions (>= 0.1.0)
|
204
|
+
websocket-extensions (0.1.4)
|
205
|
+
|
206
|
+
PLATFORMS
|
207
|
+
ruby
|
208
|
+
|
209
|
+
DEPENDENCIES
|
210
|
+
bundler
|
211
|
+
bunny
|
212
|
+
google-cloud-pubsub
|
213
|
+
pub_sub_model_sync!
|
214
|
+
rake
|
215
|
+
rspec
|
216
|
+
rubocop
|
217
|
+
sqlite3
|
218
|
+
|
219
|
+
BUNDLED WITH
|
220
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Owen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# PubSubModelSync
|
2
|
+
Permit to sync models data and make calls between rails apps using google or rabbitmq pub/sub service.
|
3
|
+
|
4
|
+
Note: This gem is based on [MultipleMan](https://github.com/influitive/multiple_man) which for now looks unmaintained.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
- Sync CRUD operations between Rails apps. So, all changes made on App1, will be reflected on App2, App3.
|
8
|
+
Example: If User is created on App1, this user will be created on App2 too with the accepted attributes.
|
9
|
+
- Ability to make class level communication
|
10
|
+
Example: If User from App1 wants to generate_email, this can be listened on App2, App3, ... to make corresponding actions
|
11
|
+
- Change pub/sub service at any time
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
```ruby
|
16
|
+
gem 'pub_sub_model_sync'
|
17
|
+
gem 'google-cloud-pubsub' # to use google pub/sub service
|
18
|
+
gem 'bunny' # to use rabbit-mq pub/sub service
|
19
|
+
```
|
20
|
+
And then execute: $ bundle install
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
- Configuration for google pub/sub (You need google pub/sub service account)
|
26
|
+
```ruby
|
27
|
+
# initializers/pub_sub_config.rb
|
28
|
+
PubSubModelSync::Config.service_name = :google
|
29
|
+
PubSubModelSync::Config.project = 'project-id'
|
30
|
+
PubSubModelSync::Config.credentials = 'path-to-the-config'
|
31
|
+
PubSubModelSync::Config.topic_name = 'sample-topic'
|
32
|
+
PubSubModelSync::Config.subscription_name = 'p1-subscriber'
|
33
|
+
```
|
34
|
+
See details here:
|
35
|
+
https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
|
36
|
+
|
37
|
+
- configuration for RabbitMq (You need rabbitmq installed)
|
38
|
+
```ruby
|
39
|
+
PubSubModelSync::Config.service_name = :rabbitmq
|
40
|
+
PubSubModelSync::Config.bunny_connection = 'amqp://guest:guest@localhost'
|
41
|
+
PubSubModelSync::Config.queue_name = ''
|
42
|
+
PubSubModelSync::Config.topic_name = 'sample-topic'
|
43
|
+
```
|
44
|
+
See details here: https://github.com/ruby-amqp/bunny
|
45
|
+
|
46
|
+
- Add publishers/subscribers to your models (See examples below)
|
47
|
+
|
48
|
+
- Start listening for publishers (Only in the app that has subscribers)
|
49
|
+
```ruby
|
50
|
+
rake pub_sub_model_sync:start
|
51
|
+
```
|
52
|
+
Note: Publishers do not need todo this
|
53
|
+
|
54
|
+
## Examples
|
55
|
+
```ruby
|
56
|
+
# App 1
|
57
|
+
# attributes: name email age
|
58
|
+
class User < ActiveRecord::Base
|
59
|
+
include PubSubModelSync::PublisherConcern
|
60
|
+
ps_msync_publish(%i[name email])
|
61
|
+
end
|
62
|
+
|
63
|
+
# App 2
|
64
|
+
class User < ActiveRecord::Base
|
65
|
+
include PubSubModelSync::SubscriberConcern
|
66
|
+
ps_msync_subscribe(%i[name])
|
67
|
+
ps_msync_class_subscribe(:greeting)
|
68
|
+
|
69
|
+
def self.greeting(data)
|
70
|
+
puts 'Class message called'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Samples
|
75
|
+
User.create(name: 'test user') # Review your App 2 to see the created user (only name will be saved)
|
76
|
+
User.ps_msync_class_publish({ msg: 'Hello' }, action: :greeting) # User.greeting method (Class method) will be called in App2
|
77
|
+
```
|
78
|
+
|
79
|
+
## Advanced Example
|
80
|
+
```ruby
|
81
|
+
# App 1
|
82
|
+
class User < ActiveRecord::Base
|
83
|
+
self.table_name = 'publisher_users'
|
84
|
+
include PubSubModelSync::PublisherConcern
|
85
|
+
ps_msync_publish(%i[name], actions: %i[update], as_klass: 'Client', id: :client_id)
|
86
|
+
|
87
|
+
def ps_msync_skip_for?(_action)
|
88
|
+
false # here logic with action to skip push message
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# App 2
|
93
|
+
class User < ActiveRecord::Base
|
94
|
+
self.table_name = 'subscriber_users'
|
95
|
+
include PubSubModelSync::SubscriberConcern
|
96
|
+
ps_msync_subscribe(%i[name], actions: %i[update], as_klass: 'Client', id: :custom_id)
|
97
|
+
ps_msync_class_subscribe(:greeting, as_action: :custom_greeting, as_klass: 'CustomUser')
|
98
|
+
|
99
|
+
def self.greeting(data)
|
100
|
+
puts 'Class message called through custom_greeting'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
## Testing
|
106
|
+
- Rspec: (spec/rails_helper.rb)
|
107
|
+
```ruby
|
108
|
+
|
109
|
+
# when using google service
|
110
|
+
require 'pub_sub_model_sync/mock_google_service'
|
111
|
+
config.before(:each) do
|
112
|
+
pub_sub_mock = PubSubModelSync::MockGoogleService.new
|
113
|
+
allow(Google::Cloud::Pubsub).to receive(:new).and_return(pub_sub_mock)
|
114
|
+
end
|
115
|
+
|
116
|
+
# when using rabbitmq service
|
117
|
+
require 'pub_sub_model_sync/mock_rabbit_service'
|
118
|
+
config.before(:each) do
|
119
|
+
bunny_mock = PubSubModelSync::MockRabbitService.new
|
120
|
+
allow(Bunny).to receive(:new).and_return(bunny_mock)
|
121
|
+
end
|
122
|
+
|
123
|
+
```
|
124
|
+
- Examples:
|
125
|
+
```ruby
|
126
|
+
# Subscriber
|
127
|
+
it 'receive model message' do
|
128
|
+
action = :create
|
129
|
+
data = { name: 'name' }
|
130
|
+
user_id = 999
|
131
|
+
attrs = PubSubModelSync::Publisher.build_attrs('User', action, user_id)
|
132
|
+
publisher = PubSubModelSync::MessageProcessor.new(data, 'User', action, id: user_id)
|
133
|
+
publisher.process
|
134
|
+
expect(User.where(id: user_id).any?).to be_truth
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'receive class message' do
|
138
|
+
action = :greeting
|
139
|
+
data = { msg: 'hello' }
|
140
|
+
publisher = PubSubModelSync::MessageProcessor.new(data, 'User', action)
|
141
|
+
publisher.process
|
142
|
+
expect(User).to receive(action)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Publisher
|
146
|
+
it 'publish model action' do
|
147
|
+
publisher = PubSubModelSync::Publisher
|
148
|
+
data = { name: 'hello'}
|
149
|
+
action = :create
|
150
|
+
User.ps_msync_class_publish(data, action: action)
|
151
|
+
user = User.create(name: 'name', email: 'email')
|
152
|
+
expect_any_instance_of(publisher).to receive(:publish_model).with(user, :create, anything)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'publish class message' do
|
156
|
+
publisher = PubSubModelSync::Publisher
|
157
|
+
data = {msg: 'hello'}
|
158
|
+
action = :greeting
|
159
|
+
User.ps_msync_class_publish(data, action: action)
|
160
|
+
expect_any_instance_of(publisher).to receive(:publish_data).with('User', data, action)
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
There are two special methods to extract crud configuration settings (attrs, id, ...):
|
165
|
+
|
166
|
+
Subscribers: ```User.ps_msync_subscriber_settings```
|
167
|
+
|
168
|
+
Publishers: ```User.ps_msync_publisher_settings```
|
169
|
+
|
170
|
+
Note: Inspect all configured listeners with:
|
171
|
+
``` PubSubModelSync::Config.listeners ```
|
172
|
+
|
173
|
+
## Contributing
|
174
|
+
|
175
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/owen2345/pub_sub_model_sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
180
|
+
|
181
|
+
## Code of Conduct
|
182
|
+
|
183
|
+
Everyone interacting in the PubSubModelSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pub_sub_model_sync/blob/master/CODE_OF_CONDUCT.md).
|