strum-esb 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +11 -1
- data/Gemfile +4 -3
- data/Gemfile.lock +44 -31
- data/lib/strum/esb/functions.rb +1 -1
- data/lib/strum/esb/handler.rb +5 -2
- data/lib/strum/esb/message.rb +48 -16
- data/lib/strum/esb/serializer.rb +2 -0
- data/lib/strum/esb/version.rb +1 -1
- data/lib/strum/esb.rb +7 -7
- 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: 71859024cac83efb0fe65d36972bc59e3a36aa909b8dd01c3a048e1c302c6af2
|
4
|
+
data.tar.gz: 3c85a148cdd144bd1f7dab17cece39d33f2dea8ea17813a77353cf4cadbe2ecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94e6c04dc46f018558bb04b1edc16108cab4199e15eaebef3c3520d3e334828150dd524c02ce8005cc8f503207af7ff19c1f6d09ca98462ca0d4889cc4897e9
|
7
|
+
data.tar.gz: '09c5454b9283ce7b6c4be64d804bfe8b42894fb52afae00c3296107172cbe3be1841caaed160888b9ba5c3b12d41493b76b4a9fe451d714eaf05f7f7a63fdb47'
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -23,4 +23,14 @@ Style/StringLiterals:
|
|
23
23
|
|
24
24
|
Metrics/LineLength:
|
25
25
|
Max: 120
|
26
|
-
|
26
|
+
AllowedPatterns: ['\A[^#].*']
|
27
|
+
|
28
|
+
Gemspec/RequireMFA:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/Documentation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/BlockLength:
|
35
|
+
Exclude:
|
36
|
+
- 'spec/**/*.rb'
|
data/Gemfile
CHANGED
@@ -6,9 +6,10 @@ source "https://rubygems.org"
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
gem "bundler", "~> 2.1.4"
|
9
|
-
gem "rspec", "~> 3.
|
10
|
-
gem "rubocop", "~> 1.
|
11
|
-
gem "rubocop-rspec", "~> 2.
|
9
|
+
gem "rspec", "~> 3.12.0"
|
10
|
+
gem "rubocop", "~> 1.49.0"
|
11
|
+
gem "rubocop-rspec", "~> 2.19"
|
12
|
+
gem "simplecov", "~> 0.22.0"
|
12
13
|
|
13
14
|
gem "debase", "~> 0.2.5.beta2"
|
14
15
|
gem "ruby-debug-ide", "~> 0.7.2"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strum-esb (0.4.
|
4
|
+
strum-esb (0.4.1)
|
5
5
|
bunny (~> 2.15)
|
6
6
|
connection_pool (~> 2.2.2)
|
7
7
|
dry-configurable (~> 0.12.1)
|
@@ -14,64 +14,75 @@ GEM
|
|
14
14
|
specs:
|
15
15
|
amq-protocol (2.3.2)
|
16
16
|
ast (2.4.2)
|
17
|
-
bunny (2.
|
17
|
+
bunny (2.20.3)
|
18
18
|
amq-protocol (~> 2.3, >= 2.3.1)
|
19
19
|
sorted_set (~> 1, >= 1.0.2)
|
20
|
-
concurrent-ruby (1.
|
20
|
+
concurrent-ruby (1.2.2)
|
21
21
|
connection_pool (2.2.5)
|
22
22
|
debase (0.2.5.beta2)
|
23
23
|
debase-ruby_core_source (>= 0.10.12)
|
24
24
|
debase-ruby_core_source (0.10.14)
|
25
25
|
diff-lcs (1.5.0)
|
26
|
+
docile (1.4.0)
|
26
27
|
dry-configurable (0.12.1)
|
27
28
|
concurrent-ruby (~> 1.0)
|
28
29
|
dry-core (~> 0.5, >= 0.5.0)
|
29
|
-
dry-core (0.
|
30
|
+
dry-core (0.9.1)
|
30
31
|
concurrent-ruby (~> 1.0)
|
32
|
+
zeitwerk (~> 2.6)
|
31
33
|
dry-inflector (0.2.1)
|
32
34
|
json (2.6.2)
|
33
35
|
parallel (1.22.1)
|
34
|
-
parser (3.
|
36
|
+
parser (3.2.2.0)
|
35
37
|
ast (~> 2.4.1)
|
36
38
|
rainbow (3.1.1)
|
37
39
|
rake (12.3.3)
|
38
|
-
rbtree (0.4.
|
39
|
-
regexp_parser (2.
|
40
|
+
rbtree (0.4.6)
|
41
|
+
regexp_parser (2.7.0)
|
40
42
|
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.
|
43
|
+
rspec (3.12.0)
|
44
|
+
rspec-core (~> 3.12.0)
|
45
|
+
rspec-expectations (~> 3.12.0)
|
46
|
+
rspec-mocks (~> 3.12.0)
|
47
|
+
rspec-core (3.12.1)
|
48
|
+
rspec-support (~> 3.12.0)
|
49
|
+
rspec-expectations (3.12.2)
|
48
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-mocks (3.
|
51
|
+
rspec-support (~> 3.12.0)
|
52
|
+
rspec-mocks (3.12.5)
|
51
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-support (3.
|
54
|
-
rubocop (1.
|
54
|
+
rspec-support (~> 3.12.0)
|
55
|
+
rspec-support (3.12.0)
|
56
|
+
rubocop (1.49.0)
|
55
57
|
json (~> 2.3)
|
56
58
|
parallel (~> 1.10)
|
57
|
-
parser (>= 3.
|
59
|
+
parser (>= 3.2.0.0)
|
58
60
|
rainbow (>= 2.2.2, < 4.0)
|
59
61
|
regexp_parser (>= 1.8, < 3.0)
|
60
62
|
rexml (>= 3.2.5, < 4.0)
|
61
|
-
rubocop-ast (>= 1.
|
63
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
62
64
|
ruby-progressbar (~> 1.7)
|
63
|
-
unicode-display_width (>=
|
64
|
-
rubocop-ast (1.
|
65
|
-
parser (>= 3.
|
66
|
-
rubocop-
|
67
|
-
rubocop (~> 1.
|
65
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
66
|
+
rubocop-ast (1.28.0)
|
67
|
+
parser (>= 3.2.1.0)
|
68
|
+
rubocop-capybara (2.17.1)
|
69
|
+
rubocop (~> 1.41)
|
70
|
+
rubocop-rspec (2.19.0)
|
71
|
+
rubocop (~> 1.33)
|
72
|
+
rubocop-capybara (~> 2.17)
|
68
73
|
ruby-debug-ide (0.7.3)
|
69
74
|
rake (>= 0.8.1)
|
70
|
-
ruby-progressbar (1.
|
75
|
+
ruby-progressbar (1.13.0)
|
71
76
|
serverengine (2.1.1)
|
72
77
|
sigdump (~> 0.2.2)
|
73
78
|
set (1.0.3)
|
74
79
|
sigdump (0.2.4)
|
80
|
+
simplecov (0.22.0)
|
81
|
+
docile (~> 1.1)
|
82
|
+
simplecov-html (~> 0.11)
|
83
|
+
simplecov_json_formatter (~> 0.1)
|
84
|
+
simplecov-html (0.12.3)
|
85
|
+
simplecov_json_formatter (0.1.4)
|
75
86
|
sneakers (2.12.0)
|
76
87
|
bunny (~> 2.14)
|
77
88
|
concurrent-ruby (~> 1.0)
|
@@ -82,7 +93,8 @@ GEM
|
|
82
93
|
rbtree
|
83
94
|
set (~> 1.0)
|
84
95
|
thor (1.2.1)
|
85
|
-
unicode-display_width (2.2
|
96
|
+
unicode-display_width (2.4.2)
|
97
|
+
zeitwerk (2.6.7)
|
86
98
|
|
87
99
|
PLATFORMS
|
88
100
|
ruby
|
@@ -91,10 +103,11 @@ DEPENDENCIES
|
|
91
103
|
bundler (~> 2.1.4)
|
92
104
|
debase (~> 0.2.5.beta2)
|
93
105
|
dry-inflector (~> 0.2.1)
|
94
|
-
rspec (~> 3.
|
95
|
-
rubocop (~> 1.
|
96
|
-
rubocop-rspec (~> 2.
|
106
|
+
rspec (~> 3.12.0)
|
107
|
+
rubocop (~> 1.49.0)
|
108
|
+
rubocop-rspec (~> 2.19)
|
97
109
|
ruby-debug-ide (~> 0.7.2)
|
110
|
+
simplecov (~> 0.22.0)
|
98
111
|
strum-esb!
|
99
112
|
|
100
113
|
BUNDLED WITH
|
data/lib/strum/esb/functions.rb
CHANGED
@@ -18,7 +18,7 @@ module Strum
|
|
18
18
|
|
19
19
|
def notice_explain(source)
|
20
20
|
exchange, resource_notice = source.include?(":") ? source.split(":") : [Strum::Esb.config.notice_exchange, source]
|
21
|
-
resource, notice
|
21
|
+
resource, notice = resource_notice.split("/")
|
22
22
|
[exchange, resource, notice]
|
23
23
|
end
|
24
24
|
|
data/lib/strum/esb/handler.rb
CHANGED
@@ -138,9 +138,12 @@ module Strum
|
|
138
138
|
error = nil
|
139
139
|
method_params = method(method_name)
|
140
140
|
.parameters
|
141
|
-
.map
|
141
|
+
.map do |param|
|
142
|
+
_, param_name = param
|
143
|
+
param_name
|
144
|
+
end
|
142
145
|
.then { |m| m & %I[action resource event state info pipeline pipeline_id] }
|
143
|
-
handler_params = method_params.each_with_object({}) { |i, res| res[i] = eval(i.to_s)
|
146
|
+
handler_params = method_params.each_with_object({}) { |i, res| res[i] = eval(i.to_s) }
|
144
147
|
logger.info("Handler #{method_name} found. Payload: #{payload}")
|
145
148
|
handler_params.count.positive? ? send(method_name, payload, handler_params) : send(method_name, payload)
|
146
149
|
logger.info("Handler #{method_name} executed")
|
data/lib/strum/esb/message.rb
CHANGED
@@ -4,28 +4,60 @@ module Strum
|
|
4
4
|
module Esb
|
5
5
|
# Strum Message
|
6
6
|
class Message
|
7
|
+
FROZEN_EXCHANGE_OPTIONS = { durable: true }.freeze
|
8
|
+
|
7
9
|
class << self
|
8
|
-
def publish(exchange:, headers:, payload:, **args)
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def publish(exchange:, headers:, payload:, exchange_options: {}, **args)
|
11
|
+
new(
|
12
|
+
exchange: exchange,
|
13
|
+
headers: headers,
|
14
|
+
payload: payload,
|
15
|
+
exchange_options: exchange_options,
|
16
|
+
**args
|
17
|
+
).publish
|
18
|
+
end
|
19
|
+
end
|
12
20
|
|
13
|
-
|
21
|
+
attr_reader :exchange,
|
22
|
+
:headers,
|
23
|
+
:payload,
|
24
|
+
:args,
|
25
|
+
:exchange_options,
|
26
|
+
:rabbit_channel
|
14
27
|
|
15
|
-
|
16
|
-
|
28
|
+
def initialize(exchange:, headers:, payload:, exchange_options: {}, **args)
|
29
|
+
@exchange = exchange
|
30
|
+
@headers = headers
|
31
|
+
@payload = payload
|
32
|
+
@args = args # { content_type: "application/x-protobuf", message_class: Messages::ActionGetUser }
|
33
|
+
# Sneakers::CONFIG[:exchange_options] = { type: "headers", durable: true, auto_delete: false, arguments: {} }
|
34
|
+
@exchange_options = Sneakers::CONFIG[:exchange_options].merge(exchange_options).merge(FROZEN_EXCHANGE_OPTIONS)
|
35
|
+
@rabbit_channel = Strum::Esb.config.rabbit_channel_pool
|
36
|
+
end
|
17
37
|
|
18
|
-
|
19
|
-
|
38
|
+
def publish
|
39
|
+
rabbit_exchange = rabbit_channel.with { |rabbit_channel| rabbit_channel.headers(exchange, exchange_options) }
|
40
|
+
payload, valid_payload, properties = prepare_publication_options
|
41
|
+
return unless valid_payload
|
20
42
|
|
21
|
-
|
22
|
-
|
43
|
+
rabbit_exchange.publish(payload, **properties)
|
44
|
+
end
|
23
45
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
46
|
+
def prepare_publication_options
|
47
|
+
properties = { headers: headers, content_type: args.fetch(:content_type, "application/json") }
|
48
|
+
|
49
|
+
Strum::Esb.config.before_publish_hooks.each { |hook| hook.call(payload, properties) }
|
50
|
+
extend_headers(properties)
|
51
|
+
args.merge!(properties)
|
52
|
+
|
53
|
+
# [serialized_payload, valid, properties]
|
54
|
+
[*Strum::Esb.config.serializer.serialize(payload, args: args), properties]
|
55
|
+
end
|
56
|
+
|
57
|
+
def extend_headers(properties)
|
58
|
+
properties[:headers] = {} unless properties[:headers].is_a?(Hash)
|
59
|
+
properties[:headers]["pipeline"] ||= Thread.current[:pipeline] if Thread.current[:pipeline]
|
60
|
+
properties[:headers]["pipeline-id"] ||= Thread.current[:pipeline_id] if Thread.current[:pipeline_id]
|
29
61
|
end
|
30
62
|
end
|
31
63
|
end
|
data/lib/strum/esb/serializer.rb
CHANGED
data/lib/strum/esb/version.rb
CHANGED
data/lib/strum/esb.rb
CHANGED
@@ -29,12 +29,12 @@ module Strum
|
|
29
29
|
setting :action_exchange, "strum.actions"
|
30
30
|
setting :notice_exchange, "strum.notice"
|
31
31
|
setting :rabbit_channel_pool, begin
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
ConnectionPool.new(size: 5, timeout: 5) do
|
33
|
+
rabbit_connection = Bunny.new
|
34
|
+
rabbit_connection.start
|
35
|
+
rabbit_connection.create_channel
|
36
|
+
end
|
37
|
+
end
|
38
38
|
setting :before_fork_hooks, []
|
39
39
|
setting :after_fork_hooks, []
|
40
40
|
setting :before_publish_hooks, []
|
@@ -49,7 +49,7 @@ module Strum
|
|
49
49
|
message_class.new(payload).to_proto
|
50
50
|
end,
|
51
51
|
from_proto: proc do |message_class, encoded_payload|
|
52
|
-
message_class.decode(encoded_payload)
|
52
|
+
message_class.decode(encoded_payload)
|
53
53
|
end
|
54
54
|
}
|
55
55
|
|
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serhiy Nazarov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|