maitredee 0.8.3 → 0.8.4
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 +4 -4
- data/.circleci/config.yml +1 -1
- data/.ruby-version +1 -1
- data/.yardopts +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +7 -5
- data/README.md +41 -16
- data/lib/maitredee.rb +2 -2
- data/lib/maitredee/active_job.rb +2 -0
- data/lib/maitredee/adapters/sns_sqs_adapter.rb +1 -0
- data/lib/maitredee/adapters/test_adapter.rb +25 -0
- data/lib/maitredee/cli/runner.rb +1 -0
- data/lib/maitredee/publisher.rb +24 -10
- data/lib/maitredee/railtie.rb +1 -0
- data/lib/maitredee/subscriber.rb +31 -11
- data/lib/maitredee/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d1707193034f7c326212f91d003ce1fab80587ede4f5cc0c19bffbe3cf856d19
|
|
4
|
+
data.tar.gz: 226103487e3a17348f9e89d2a82b195e55cd07d5f3a404a8598da71dbcb15417
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f07e5f444fb7bd2869a20793fc5e06afd7d43a378a17ece9a0a5940ac8f88927e75b839992d3a13d1094b7b62c8022fedae4c70ef3260382a69095cfe5bb938a
|
|
7
|
+
data.tar.gz: 16e90e3d7fa22cd31f12ecd84212bb365efd397f793a1b5ed4b254448f67df5fc7fed8e89d7e784292b068ecc59e842d0dd6a7fd403e877e054ca5dd64efcb32
|
data/.circleci/config.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.6.0
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
maitredee (0.8.
|
|
4
|
+
maitredee (0.8.4)
|
|
5
5
|
activesupport
|
|
6
6
|
aws-sdk-sns
|
|
7
7
|
aws-sdk-sqs
|
|
@@ -34,8 +34,8 @@ GEM
|
|
|
34
34
|
minitest (~> 5.1)
|
|
35
35
|
tzinfo (~> 1.1)
|
|
36
36
|
aws-eventstream (1.0.1)
|
|
37
|
-
aws-partitions (1.
|
|
38
|
-
aws-sdk-core (3.44.
|
|
37
|
+
aws-partitions (1.129.0)
|
|
38
|
+
aws-sdk-core (3.44.2)
|
|
39
39
|
aws-eventstream (~> 1.0)
|
|
40
40
|
aws-partitions (~> 1.0)
|
|
41
41
|
aws-sigv4 (~> 1.0)
|
|
@@ -68,7 +68,7 @@ GEM
|
|
|
68
68
|
i18n (1.1.1)
|
|
69
69
|
concurrent-ruby (~> 1.0)
|
|
70
70
|
jmespath (1.4.0)
|
|
71
|
-
json_schemer (0.1.
|
|
71
|
+
json_schemer (0.1.10)
|
|
72
72
|
ecma-re-validator (~> 0.2.0)
|
|
73
73
|
hana (~> 1.3.3)
|
|
74
74
|
regexp_parser (~> 1.2.0)
|
|
@@ -116,7 +116,7 @@ GEM
|
|
|
116
116
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
117
117
|
rspec-support (~> 3.8.0)
|
|
118
118
|
rspec-support (3.8.0)
|
|
119
|
-
shoryuken (4.0.
|
|
119
|
+
shoryuken (4.0.3)
|
|
120
120
|
aws-sdk-core (>= 2)
|
|
121
121
|
concurrent-ruby
|
|
122
122
|
thor
|
|
@@ -125,6 +125,7 @@ GEM
|
|
|
125
125
|
tzinfo (1.2.5)
|
|
126
126
|
thread_safe (~> 0.1)
|
|
127
127
|
uri_template (0.7.0)
|
|
128
|
+
yard (0.9.16)
|
|
128
129
|
|
|
129
130
|
PLATFORMS
|
|
130
131
|
ruby
|
|
@@ -141,6 +142,7 @@ DEPENDENCIES
|
|
|
141
142
|
rake (~> 10.0)
|
|
142
143
|
rspec (~> 3.0)
|
|
143
144
|
rspec-mocks (~> 3.0)
|
|
145
|
+
yard
|
|
144
146
|
|
|
145
147
|
BUNDLED WITH
|
|
146
148
|
1.17.2
|
data/README.md
CHANGED
|
@@ -8,6 +8,7 @@ An opinionated pub/sub framework.
|
|
|
8
8
|
- [Configuration](#configuration)
|
|
9
9
|
- [Publisher](#publisher)
|
|
10
10
|
- [Subscriber](#subscriber)
|
|
11
|
+
- [Listening to messages](#listening-to-messages)
|
|
11
12
|
- [Validation schema](#validation-schema)
|
|
12
13
|
- [Misc](#misc)
|
|
13
14
|
- [Development](#development)
|
|
@@ -22,6 +23,8 @@ We tried to have zero setup required to get this up and running and make it work
|
|
|
22
23
|
|
|
23
24
|
We hope in the future to add more adapters beyond sns/sqs.
|
|
24
25
|
|
|
26
|
+
For API docks visit https://www.rubydoc.info/gems/maitredee
|
|
27
|
+
|
|
25
28
|
## Installation
|
|
26
29
|
|
|
27
30
|
Add this line to your application's Gemfile:
|
|
@@ -84,49 +87,51 @@ You should reset the client at the beginning of every test with `Maitredee.clien
|
|
|
84
87
|
|
|
85
88
|
Create a publisher class for your topic and inherit from `Maitredee::Publisher`
|
|
86
89
|
Optionally define the default topic, event_name, or validation schema with `publish_defaults`
|
|
87
|
-
|
|
90
|
+
Define an `#initialize` and `#process`. `#process` will get called when you execute the publisher.
|
|
91
|
+
Call `#publish` from `#process` to publish messages. `#publish` will default the parameters `topic`, `event_name`, and `schema_name` from your `.publish_defaults` if not given.
|
|
88
92
|
|
|
89
93
|
```ruby goodread
|
|
90
94
|
require "maitredee"
|
|
91
95
|
|
|
92
|
-
class
|
|
96
|
+
class RecipePublisher < Maitredee::Publisher
|
|
93
97
|
publish_defaults(
|
|
94
|
-
topic_name: :
|
|
95
|
-
event_name: :
|
|
96
|
-
schema_name: :
|
|
98
|
+
topic_name: :default_topic,
|
|
99
|
+
event_name: :optional_default_event_name,
|
|
100
|
+
schema_name: :default_schema
|
|
97
101
|
)
|
|
98
102
|
|
|
99
|
-
attr_reader :
|
|
103
|
+
attr_reader :recipe
|
|
100
104
|
|
|
101
|
-
def initialize(
|
|
102
|
-
@
|
|
105
|
+
def initialize(recipe)
|
|
106
|
+
@recipe = recipe
|
|
103
107
|
end
|
|
104
108
|
|
|
105
109
|
def process
|
|
106
110
|
publish(
|
|
107
|
-
topic_name: :
|
|
111
|
+
topic_name: :my_topic_override,
|
|
108
112
|
event_name: :event_name_is_optional,
|
|
109
113
|
schema_name: :schema_name,
|
|
110
114
|
primary_key: "optionalKey",
|
|
111
115
|
body: {
|
|
112
|
-
id:
|
|
113
|
-
name:
|
|
116
|
+
id: recipe.id,
|
|
117
|
+
name: recipe.name
|
|
114
118
|
}
|
|
115
119
|
)
|
|
116
120
|
end
|
|
117
121
|
end
|
|
118
122
|
```
|
|
119
123
|
|
|
120
|
-
|
|
121
124
|
### Publishing a message
|
|
122
|
-
To publish a message, simply call
|
|
125
|
+
To publish a message, simply call `.call` on your publisher:
|
|
123
126
|
```ruby
|
|
124
|
-
|
|
127
|
+
RecipePublisher.call(model)
|
|
125
128
|
```
|
|
126
129
|
|
|
127
|
-
|
|
130
|
+
By default `.call` delegate the arguments to `.new` then call `#process` and return `#published_messages` which is an array of published messages.
|
|
131
|
+
|
|
132
|
+
`#publish` will first validate your schema before publishing the message.
|
|
128
133
|
|
|
129
|
-
If you have ActiveJob you can also `#call_later` and it will be called asyncronously
|
|
134
|
+
If you have ActiveJob configured you can also `#call_later` and it will be called asyncronously
|
|
130
135
|
|
|
131
136
|
## Subscriber
|
|
132
137
|
|
|
@@ -148,6 +153,12 @@ class RecipeSubscriber < Maitredee::Subscriber
|
|
|
148
153
|
default_event to: :process
|
|
149
154
|
end
|
|
150
155
|
|
|
156
|
+
# optional initializer to do message pre processing
|
|
157
|
+
# def initialize(message)
|
|
158
|
+
# super
|
|
159
|
+
# # do business here
|
|
160
|
+
# end
|
|
161
|
+
|
|
151
162
|
def create
|
|
152
163
|
Recipe.create!(message.body)
|
|
153
164
|
end
|
|
@@ -162,6 +173,20 @@ class RecipeSubscriber < Maitredee::Subscriber
|
|
|
162
173
|
end
|
|
163
174
|
```
|
|
164
175
|
|
|
176
|
+
## Listening to messages
|
|
177
|
+
We use shoryuken as our worker backend. Maitredee supports all shoryuken options except queues which is replace with subscribers.
|
|
178
|
+
|
|
179
|
+
https://github.com/phstc/shoryuken/wiki/Shoryuken-options
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
subscribers:
|
|
183
|
+
- RecipeSubscriber
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```sh
|
|
187
|
+
maitredee -s RecipeSubscriber
|
|
188
|
+
```
|
|
189
|
+
|
|
165
190
|
## Validating Schemas
|
|
166
191
|
Maitredee validates your message body schemas using JSON schema ([JSON-schemer] (https://github.com/davishmcclurg/json_schemer)) for both publishing and consuming messages. [Configure] (#configuration) the location of your schemas and provide a JSON file for each of your schemas.
|
|
167
192
|
|
data/lib/maitredee.rb
CHANGED
|
@@ -138,7 +138,7 @@ module Maitredee
|
|
|
138
138
|
end
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
# fetch configured app name or automatically fetch from Rails or from ENV["MAITREDEE_APP_NAME"]
|
|
141
|
+
# fetch configured app name or automatically fetch from Rails or from `ENV["MAITREDEE_APP_NAME"]`
|
|
142
142
|
# used for generating queue_resource_name
|
|
143
143
|
#
|
|
144
144
|
# @return [String]
|
|
@@ -160,7 +160,7 @@ module Maitredee
|
|
|
160
160
|
attr_writer :app_name
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
# fetch configured namespace or automatically fetch from ENV["MAITREDEE_NAMESPACE"]
|
|
163
|
+
# fetch configured namespace or automatically fetch from `ENV["MAITREDEE_NAMESPACE"]`
|
|
164
164
|
# @return [String]
|
|
165
165
|
def namespace
|
|
166
166
|
@namespace ||=
|
data/lib/maitredee/active_job.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Maitredee
|
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
# @api private
|
|
12
13
|
def self.create_publisher_job(subclass)
|
|
13
14
|
subclass.const_set("PublisherJob", Class.new(BasePublisherJob))
|
|
14
15
|
subclass::PublisherJob.service_class = subclass
|
|
@@ -39,6 +40,7 @@ module Maitredee
|
|
|
39
40
|
Maitredee::ActiveJob.create_publisher_job(subclass)
|
|
40
41
|
end
|
|
41
42
|
|
|
43
|
+
# @private
|
|
42
44
|
class BasePublisherJob < ::ActiveJob::Base
|
|
43
45
|
class << self
|
|
44
46
|
attr_accessor :service_class
|
|
@@ -21,4 +21,29 @@ module Maitredee
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
class Subscriber
|
|
26
|
+
def self.test(
|
|
27
|
+
body:,
|
|
28
|
+
event_name: nil,
|
|
29
|
+
message_id: SecureRandom.uuid,
|
|
30
|
+
sent_at: Time.now,
|
|
31
|
+
primary_key: nil
|
|
32
|
+
)
|
|
33
|
+
message = SubscriberMessage.new(
|
|
34
|
+
topic_name: topic_name,
|
|
35
|
+
body: body,
|
|
36
|
+
event_name: event_name,
|
|
37
|
+
message_id: message_id,
|
|
38
|
+
sent_at: sent_at.to_i,
|
|
39
|
+
primary_key: primary_key,
|
|
40
|
+
schema_name: nil,
|
|
41
|
+
broker_message_id: message_id,
|
|
42
|
+
maitredee_version: Maitredee::VERSION,
|
|
43
|
+
raw_message: nil,
|
|
44
|
+
adapter_message: nil
|
|
45
|
+
)
|
|
46
|
+
process(message)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
24
49
|
end
|
data/lib/maitredee/cli/runner.rb
CHANGED
data/lib/maitredee/publisher.rb
CHANGED
|
@@ -2,22 +2,36 @@ module Maitredee
|
|
|
2
2
|
##
|
|
3
3
|
# Inherit from this class to easily publish messages:
|
|
4
4
|
#
|
|
5
|
-
#
|
|
5
|
+
# class RecipePublisher < Maitredee::Publisher
|
|
6
|
+
# publish_defaults(
|
|
7
|
+
# topic_name: :default_topic,
|
|
8
|
+
# event_name: :optional_default_event_name,
|
|
9
|
+
# schema_name: :default_schema
|
|
10
|
+
# )
|
|
6
11
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
12
|
+
# attr_reader :recipe
|
|
13
|
+
#
|
|
14
|
+
# def initialize(recipe)
|
|
15
|
+
# @recipe = recipe
|
|
16
|
+
# end
|
|
10
17
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
18
|
+
# def process
|
|
19
|
+
# publish(
|
|
20
|
+
# topic_name: :my_topic_override,
|
|
21
|
+
# event_name: :event_name_is_optional,
|
|
22
|
+
# schema_name: :schema_name,
|
|
23
|
+
# primary_key: "optionalKey",
|
|
24
|
+
# body: {
|
|
25
|
+
# id: recipe.id,
|
|
26
|
+
# name: recipe.name
|
|
27
|
+
# }
|
|
28
|
+
# )
|
|
29
|
+
# end
|
|
13
30
|
# end
|
|
14
|
-
# end
|
|
15
31
|
#
|
|
16
32
|
# Then in your Rails app, you can do this:
|
|
17
33
|
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# Note that `call` is a class method, `process` is an instance method.
|
|
34
|
+
# RecipePublisher.call(1, 2, 3)
|
|
21
35
|
class Publisher
|
|
22
36
|
class << self
|
|
23
37
|
# call #process and return publishes messages
|
data/lib/maitredee/railtie.rb
CHANGED
data/lib/maitredee/subscriber.rb
CHANGED
|
@@ -4,21 +4,41 @@ module Maitredee
|
|
|
4
4
|
##
|
|
5
5
|
# Inherit from this class to easily subscrive to messages:
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# end
|
|
7
|
+
# class RecipeSubscriber < Maitredee::Subscriber
|
|
8
|
+
# # this is the topic name
|
|
9
|
+
# subscribe_to :recipes do
|
|
11
10
|
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
11
|
+
# # this is the event name optionally say which method to use to process
|
|
12
|
+
# event(:create, to: create)
|
|
13
|
+
#
|
|
14
|
+
# # event_name will be used as the method name if it is a valid method name, otherwise to: must be set
|
|
15
|
+
# event(:delete)
|
|
16
|
+
#
|
|
17
|
+
# # for empty event name just use nil
|
|
18
|
+
# event(nil, to: :process)
|
|
16
19
|
#
|
|
17
|
-
#
|
|
20
|
+
# # you can specify a catch all route
|
|
21
|
+
# default_event to: :process
|
|
22
|
+
# end
|
|
18
23
|
#
|
|
19
|
-
#
|
|
24
|
+
# # optional initializer to do message pre processing
|
|
25
|
+
# # def initialize(message)
|
|
26
|
+
# # super
|
|
27
|
+
# # # do business here
|
|
28
|
+
# # end
|
|
20
29
|
#
|
|
21
|
-
#
|
|
30
|
+
# def create
|
|
31
|
+
# Recipe.create!(message.body)
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# def process
|
|
35
|
+
# Recipe.find(message.body[:id]).update(message.body)
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# def delete
|
|
39
|
+
# Recipe.find(message.body[:id]).destroy
|
|
40
|
+
# end
|
|
41
|
+
# end
|
|
22
42
|
class Subscriber
|
|
23
43
|
EventConfig = Struct.new(
|
|
24
44
|
:action,
|
data/lib/maitredee/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maitredee
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Plated Devs
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -286,8 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
286
286
|
- !ruby/object:Gem::Version
|
|
287
287
|
version: '0'
|
|
288
288
|
requirements: []
|
|
289
|
-
|
|
290
|
-
rubygems_version: 2.7.6
|
|
289
|
+
rubygems_version: 3.0.1
|
|
291
290
|
signing_key:
|
|
292
291
|
specification_version: 4
|
|
293
292
|
summary: Opinionated pub/sub framework
|