strum-esb 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +30 -30
- data/lib/strum/esb/handler.rb +39 -30
- data/lib/strum/esb/message.rb +0 -4
- data/lib/strum/esb/version.rb +1 -1
- data/lib/strum/esb.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5eed53438b480b0f9f2faae4b2662dfb7005441bd74f62b15986d4eefeefbe7e
|
|
4
|
+
data.tar.gz: c8f52bbfc3955ca0735d1536e99fc07238ef6a823b84e602a242fad9b690646c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c4eb4852df47c231e43218243178582e860f3dc553b06f5f8f32165b27c4a7d2448f01ac690b59617b4e724927db4224b9311791df77a8aff3a70ada43b3f9a0
|
|
7
|
+
data.tar.gz: c0a6ce6875f528459031905df09bdcccc1cc1fa34e6ed6eecfa5863647b8d711b38879f8c13afb1ff915c7ce642a92637bfc7bc559df40921cd30761baab2c53
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
# Changelog
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.3]
|
|
6
|
+
### Added
|
|
7
|
+
- default content type `application/json` in handler by [@valeriia.kolisnyk]
|
|
8
|
+
|
|
9
|
+
## [0.3.2]
|
|
10
|
+
### Added
|
|
11
|
+
- autoremove thread variables before handle message (used by pipeline storage)
|
|
12
|
+
|
|
13
|
+
## [0.3.1]
|
|
14
|
+
### Removed
|
|
15
|
+
- removed `chain` support
|
|
16
|
+
### Added
|
|
17
|
+
- `bind_to` can take block for custom bindings
|
|
18
|
+
- `pipeline` and `pipeline_id` can be used as handler params
|
|
19
|
+
|
|
5
20
|
## [0.3.0] - 2022-03-14
|
|
6
21
|
### Added
|
|
7
22
|
- `content_type` option to send message by [@valeriia.kolisnyk]
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
strum-esb (0.3.
|
|
4
|
+
strum-esb (0.3.3)
|
|
5
5
|
bunny (~> 2.15)
|
|
6
6
|
connection_pool (~> 2.2.2)
|
|
7
7
|
dry-configurable (~> 0.12.1)
|
|
@@ -17,55 +17,55 @@ GEM
|
|
|
17
17
|
bunny (2.19.0)
|
|
18
18
|
amq-protocol (~> 2.3, >= 2.3.1)
|
|
19
19
|
sorted_set (~> 1, >= 1.0.2)
|
|
20
|
-
concurrent-ruby (1.1.
|
|
20
|
+
concurrent-ruby (1.1.10)
|
|
21
21
|
connection_pool (2.2.5)
|
|
22
|
-
debase (0.2.
|
|
23
|
-
debase-ruby_core_source (>= 0.10.
|
|
24
|
-
debase-ruby_core_source (0.10.
|
|
25
|
-
diff-lcs (1.
|
|
22
|
+
debase (0.2.5.beta2)
|
|
23
|
+
debase-ruby_core_source (>= 0.10.12)
|
|
24
|
+
debase-ruby_core_source (0.10.14)
|
|
25
|
+
diff-lcs (1.5.0)
|
|
26
26
|
dry-configurable (0.12.1)
|
|
27
27
|
concurrent-ruby (~> 1.0)
|
|
28
28
|
dry-core (~> 0.5, >= 0.5.0)
|
|
29
29
|
dry-core (0.7.1)
|
|
30
30
|
concurrent-ruby (~> 1.0)
|
|
31
31
|
dry-inflector (0.2.1)
|
|
32
|
-
json (2.6.
|
|
33
|
-
parallel (1.
|
|
34
|
-
parser (3.
|
|
32
|
+
json (2.6.2)
|
|
33
|
+
parallel (1.22.1)
|
|
34
|
+
parser (3.1.1.0)
|
|
35
35
|
ast (~> 2.4.1)
|
|
36
|
-
rainbow (3.
|
|
36
|
+
rainbow (3.1.1)
|
|
37
37
|
rake (12.3.3)
|
|
38
38
|
rbtree (0.4.5)
|
|
39
|
-
regexp_parser (2.
|
|
39
|
+
regexp_parser (2.2.1)
|
|
40
40
|
rexml (3.2.5)
|
|
41
|
-
rspec (3.
|
|
42
|
-
rspec-core (~> 3.
|
|
43
|
-
rspec-expectations (~> 3.
|
|
44
|
-
rspec-mocks (~> 3.
|
|
45
|
-
rspec-core (3.
|
|
46
|
-
rspec-support (~> 3.
|
|
47
|
-
rspec-expectations (3.
|
|
41
|
+
rspec (3.11.0)
|
|
42
|
+
rspec-core (~> 3.11.0)
|
|
43
|
+
rspec-expectations (~> 3.11.0)
|
|
44
|
+
rspec-mocks (~> 3.11.0)
|
|
45
|
+
rspec-core (3.11.0)
|
|
46
|
+
rspec-support (~> 3.11.0)
|
|
47
|
+
rspec-expectations (3.11.0)
|
|
48
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
49
|
-
rspec-support (~> 3.
|
|
50
|
-
rspec-mocks (3.
|
|
49
|
+
rspec-support (~> 3.11.0)
|
|
50
|
+
rspec-mocks (3.11.0)
|
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
52
|
-
rspec-support (~> 3.
|
|
53
|
-
rspec-support (3.
|
|
54
|
-
rubocop (1.
|
|
52
|
+
rspec-support (~> 3.11.0)
|
|
53
|
+
rspec-support (3.11.0)
|
|
54
|
+
rubocop (1.26.1)
|
|
55
55
|
parallel (~> 1.10)
|
|
56
|
-
parser (>= 3.
|
|
56
|
+
parser (>= 3.1.0.0)
|
|
57
57
|
rainbow (>= 2.2.2, < 4.0)
|
|
58
58
|
regexp_parser (>= 1.8, < 3.0)
|
|
59
59
|
rexml
|
|
60
|
-
rubocop-ast (>= 1.
|
|
60
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
|
61
61
|
ruby-progressbar (~> 1.7)
|
|
62
62
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
63
|
-
rubocop-ast (1.
|
|
64
|
-
parser (>= 3.
|
|
63
|
+
rubocop-ast (1.16.0)
|
|
64
|
+
parser (>= 3.1.1.0)
|
|
65
65
|
rubocop-rspec (2.3.0)
|
|
66
66
|
rubocop (~> 1.0)
|
|
67
67
|
rubocop-ast (>= 1.1.0)
|
|
68
|
-
ruby-debug-ide (0.7.
|
|
68
|
+
ruby-debug-ide (0.7.3)
|
|
69
69
|
rake (>= 0.8.1)
|
|
70
70
|
ruby-progressbar (1.11.0)
|
|
71
71
|
serverengine (2.1.1)
|
|
@@ -82,14 +82,14 @@ GEM
|
|
|
82
82
|
rbtree
|
|
83
83
|
set (~> 1.0)
|
|
84
84
|
thor (1.2.1)
|
|
85
|
-
unicode-display_width (2.
|
|
85
|
+
unicode-display_width (2.1.0)
|
|
86
86
|
|
|
87
87
|
PLATFORMS
|
|
88
88
|
ruby
|
|
89
89
|
|
|
90
90
|
DEPENDENCIES
|
|
91
91
|
bundler (~> 2.1.4)
|
|
92
|
-
debase (~> 0.2.
|
|
92
|
+
debase (~> 0.2.5.beta2)
|
|
93
93
|
dry-inflector (~> 0.2.1)
|
|
94
94
|
rspec (~> 3)
|
|
95
95
|
rubocop (~> 1.15)
|
data/lib/strum/esb/handler.rb
CHANGED
|
@@ -17,18 +17,26 @@ module Strum
|
|
|
17
17
|
module ClassMethods
|
|
18
18
|
def bind_to(queue, message_type, message_binding, handler = nil)
|
|
19
19
|
bindings ||= (queue_opts && queue_opts[:bindings]) || {}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
|
|
21
|
+
if block_given?
|
|
22
|
+
yield(bindings)
|
|
23
|
+
else
|
|
24
|
+
bindings[message_type] ||= []
|
|
25
|
+
bindings[message_type] << message_binding
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
from_queue queue, bindings: bindings
|
|
29
|
+
handlers[handler_key(message_type, message_binding)] = handler.to_s if handler
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def handler_key(message_type, message_binding)
|
|
23
33
|
_, *msg = Strum::Esb::Functions.public_send("#{message_type}_explain", message_binding)
|
|
24
|
-
@handlers ||= {}
|
|
25
34
|
params = msg.map{ |param| param&.to_s.gsub(/[^a-zA-Z0-9]/, "_")&.downcase }
|
|
26
|
-
|
|
27
|
-
@handlers[handler_key] = handler.to_s if handler
|
|
35
|
+
([message_type] + params).join("-")
|
|
28
36
|
end
|
|
29
37
|
|
|
30
38
|
def handlers
|
|
31
|
-
@handlers
|
|
39
|
+
@handlers ||= {}
|
|
32
40
|
end
|
|
33
41
|
|
|
34
42
|
def protobuf_service(service)
|
|
@@ -40,24 +48,23 @@ module Strum
|
|
|
40
48
|
end
|
|
41
49
|
end
|
|
42
50
|
|
|
51
|
+
def header(metadata, key)
|
|
52
|
+
(metadata[:headers] && metadata[:headers][key])&.to_s&.gsub(/[^a-zA-Z0-9]/, "_")&.downcase
|
|
53
|
+
end
|
|
54
|
+
|
|
43
55
|
def work_with_params(deserialized_msg, delivery_info, metadata)
|
|
44
56
|
Strum::Esb.config.before_handler_hooks.each { |hook| hook.call(deserialized_msg, delivery_info, metadata) }
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
info = header.call("info")
|
|
55
|
-
notice = header.call("notice")
|
|
56
|
-
Thread.current[:chain] = header.call("chain")
|
|
57
|
-
Thread.current[:pipeline] = header.call("pipeline")
|
|
58
|
-
Thread.current[:pipeline_id] = header.call("pipeline-id")
|
|
58
|
+
action = header(metadata, "action")
|
|
59
|
+
resource = header(metadata, "resource")
|
|
60
|
+
event = header(metadata, "event")
|
|
61
|
+
state = header(metadata, "state")
|
|
62
|
+
info = header(metadata, "info")
|
|
63
|
+
notice = header(metadata, "notice")
|
|
64
|
+
pipeline = Thread.current[:pipeline] = header(metadata, "pipeline")
|
|
65
|
+
pipeline_id = Thread.current[:pipeline_id] = header(metadata, "pipeline-id")
|
|
59
66
|
|
|
60
|
-
after_headers_hook
|
|
67
|
+
after_headers_hook(binding)
|
|
61
68
|
|
|
62
69
|
methods_names = if action
|
|
63
70
|
action_handler_methods(action, resource)
|
|
@@ -71,20 +78,22 @@ module Strum
|
|
|
71
78
|
|
|
72
79
|
method_name = ([*methods_names] << "handler").find { |n| respond_to?(n, include_all: true) }
|
|
73
80
|
|
|
74
|
-
unless
|
|
75
|
-
logger.error "
|
|
81
|
+
unless method_name
|
|
82
|
+
logger.error "Handler not found. Message rejected #{metadata[:headers]} with payload #{deserialized_msg}"
|
|
76
83
|
return reject!
|
|
77
84
|
end
|
|
78
85
|
|
|
79
|
-
|
|
86
|
+
content_type = metadata[:content_type] || "application/json"
|
|
80
87
|
|
|
81
|
-
unless
|
|
82
|
-
logger.error "Content type is
|
|
88
|
+
unless Strum::Esb.config.serializer.enabled?(content_type)
|
|
89
|
+
logger.error "Content type #{content_type} is disabled by handler. Message rejected #{metadata[:headers]} with payload #{deserialized_msg}"
|
|
83
90
|
return reject!
|
|
84
91
|
end
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
payload, valid_payload = Strum::Esb.config.serializer.deserialize(deserialized_msg, content_type, method_name)
|
|
94
|
+
|
|
95
|
+
unless valid_payload
|
|
96
|
+
logger.error "Payload was unable to be parsed with #{content_type} content type. Message rejected #{metadata[:headers]} with payload #{payload}"
|
|
88
97
|
return reject!
|
|
89
98
|
end
|
|
90
99
|
|
|
@@ -92,7 +101,7 @@ module Strum
|
|
|
92
101
|
method_params = method(method_name)
|
|
93
102
|
.parameters
|
|
94
103
|
.map { |param| _, param_name = param; param_name }
|
|
95
|
-
.then { |m| m & %I[action resource event state info
|
|
104
|
+
.then { |m| m & %I[action resource event state info pipeline pipeline_id] }
|
|
96
105
|
handler_params = method_params.each_with_object({}) { |i, res| res[i] = eval(i.to_s); }
|
|
97
106
|
logger.info("Handler #{method_name} found. Payload: #{payload}")
|
|
98
107
|
handler_params.count.positive? ? send(method_name, payload, handler_params) : send(method_name, payload)
|
|
@@ -106,7 +115,7 @@ module Strum
|
|
|
106
115
|
Strum::Esb.config.after_handler_hooks.each { |hook| hook.call(deserialized_msg, delivery_info, metadata, payload, error) }
|
|
107
116
|
end
|
|
108
117
|
|
|
109
|
-
def after_headers_hook; end
|
|
118
|
+
def after_headers_hook(bind); end
|
|
110
119
|
|
|
111
120
|
private
|
|
112
121
|
|
|
@@ -144,7 +153,7 @@ module Strum
|
|
|
144
153
|
result << "notice_#{notice}"
|
|
145
154
|
result << "notice_handler"
|
|
146
155
|
result
|
|
147
|
-
end
|
|
156
|
+
end
|
|
148
157
|
end
|
|
149
158
|
end
|
|
150
159
|
end
|
data/lib/strum/esb/message.rb
CHANGED
|
@@ -17,10 +17,6 @@ module Strum
|
|
|
17
17
|
properties[:headers] = {} unless properties[:headers].is_a?(Hash)
|
|
18
18
|
properties[:headers]["pipeline"] ||= Thread.current[:pipeline] if Thread.current[:pipeline]
|
|
19
19
|
properties[:headers]["pipeline-id"] ||= Thread.current[:pipeline_id] if Thread.current[:pipeline_id]
|
|
20
|
-
if (chain = Thread.current[:chain])
|
|
21
|
-
payload["chain"] ||= chain
|
|
22
|
-
headers["chain"] ||= chain
|
|
23
|
-
end
|
|
24
20
|
|
|
25
21
|
payload, valid_payload = Strum::Esb.config.serializer.serialize(payload, properties[:content_type])
|
|
26
22
|
unless valid_payload
|
data/lib/strum/esb/version.rb
CHANGED
data/lib/strum/esb.rb
CHANGED
|
@@ -51,6 +51,18 @@ module Strum
|
|
|
51
51
|
|
|
52
52
|
class Error < StandardError; end
|
|
53
53
|
|
|
54
|
+
class ThreadVariablesCleaner
|
|
55
|
+
def initialize(app, *args)
|
|
56
|
+
@app = app
|
|
57
|
+
@args = args
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def call(deserialized_msg, delivery_info, metadata, handler)
|
|
61
|
+
Thread.current.keys.each{ |key| Thread.current[key] = nil }
|
|
62
|
+
@app.call(deserialized_msg, delivery_info, metadata, handler)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
54
66
|
Sneakers.configure(
|
|
55
67
|
log: $stdout,
|
|
56
68
|
workers: Strum::Esb.config.sneakers_workers,
|
|
@@ -61,6 +73,7 @@ module Strum
|
|
|
61
73
|
exchange: Strum::Esb.config.exchange,
|
|
62
74
|
exchange_type: "headers"
|
|
63
75
|
)
|
|
76
|
+
Sneakers.middleware.use(ThreadVariablesCleaner, nil)
|
|
64
77
|
Sneakers.logger.level = Logger::INFO
|
|
65
78
|
end
|
|
66
79
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: strum-esb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Serhiy Nazarov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|