strum-esb 0.3.3 → 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 +47 -34
- data/README.md +19 -6
- data/lib/strum/esb/functions.rb +1 -1
- data/lib/strum/esb/handler.rb +53 -12
- data/lib/strum/esb/message.rb +48 -16
- data/lib/strum/esb/serializer.rb +19 -23
- data/lib/strum/esb/version.rb +1 -1
- data/lib/strum/esb.rb +20 -11
- 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
|
+
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)
|
57
|
+
json (~> 2.3)
|
55
58
|
parallel (~> 1.10)
|
56
|
-
parser (>= 3.
|
59
|
+
parser (>= 3.2.0.0)
|
57
60
|
rainbow (>= 2.2.2, < 4.0)
|
58
61
|
regexp_parser (>= 1.8, < 3.0)
|
59
|
-
rexml
|
60
|
-
rubocop-ast (>= 1.
|
62
|
+
rexml (>= 3.2.5, < 4.0)
|
63
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
61
64
|
ruby-progressbar (~> 1.7)
|
62
|
-
unicode-display_width (>=
|
63
|
-
rubocop-ast (1.
|
64
|
-
parser (>= 3.
|
65
|
-
rubocop-
|
66
|
-
rubocop (~> 1.
|
67
|
-
|
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
|
-
set (1.0.
|
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.
|
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/README.md
CHANGED
@@ -106,8 +106,9 @@ module Queues
|
|
106
106
|
class Resource
|
107
107
|
include Strum::Esb::Handler
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
enable_json false
|
110
|
+
enable_protobuf true
|
111
|
+
use_protobuf_service Test::Router::Service
|
111
112
|
from_queue "resource-queue",
|
112
113
|
bindings: {
|
113
114
|
events: %w[user/create user/update],
|
@@ -125,12 +126,24 @@ Your rpc action must have the same name as your method in queue class, for examp
|
|
125
126
|
|
126
127
|
3. Pass content type as additional param when you send Strum::Esb message:
|
127
128
|
```ruby
|
128
|
-
|
129
|
+
message = { id: 10 }
|
130
|
+
args = {
|
131
|
+
content_type: "application/x-protobuf",
|
132
|
+
message_class: Messages::ActionGetUser
|
133
|
+
}
|
134
|
+
Strum::Esb::Action.call(message, "action", "resource", **args)
|
129
135
|
```
|
130
|
-
|
136
|
+
|
137
|
+
4. Configure proto serialization/deserialization:
|
131
138
|
```ruby
|
132
|
-
Strum::Esb.config.
|
133
|
-
|
139
|
+
Strum::Esb.config.serializer_conf = {
|
140
|
+
to_proto: proc do |message_class, payload|
|
141
|
+
::CustomSerializer.to_protobuf(message_class, payload).to_proto
|
142
|
+
end,
|
143
|
+
from_proto: proc do |message_class, encoded_payload|
|
144
|
+
rpc_instance = message_class.decode(encoded_payload)
|
145
|
+
::CustomSerializer.from_protobuf(rpc_instance)
|
146
|
+
end
|
134
147
|
}
|
135
148
|
```
|
136
149
|
|
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
@@ -12,6 +12,7 @@ module Strum
|
|
12
12
|
include Sneakers::Worker
|
13
13
|
end
|
14
14
|
base.extend ClassMethods
|
15
|
+
base.use_application_config
|
15
16
|
end
|
16
17
|
|
17
18
|
module ClassMethods
|
@@ -22,16 +23,16 @@ module Strum
|
|
22
23
|
yield(bindings)
|
23
24
|
else
|
24
25
|
bindings[message_type] ||= []
|
25
|
-
bindings[message_type] << message_binding
|
26
|
+
bindings[message_type] << message_binding
|
26
27
|
end
|
27
28
|
|
28
29
|
from_queue queue, bindings: bindings
|
29
|
-
handlers[handler_key(message_type, message_binding)] = handler.to_s if handler
|
30
|
+
handlers[handler_key(message_type, message_binding)] = handler.to_s if handler
|
30
31
|
end
|
31
32
|
|
32
33
|
def handler_key(message_type, message_binding)
|
33
34
|
_, *msg = Strum::Esb::Functions.public_send("#{message_type}_explain", message_binding)
|
34
|
-
params = msg.map{ |param| param&.to_s
|
35
|
+
params = msg.map { |param| param&.to_s&.gsub(/[^a-zA-Z0-9]/, "_")&.downcase }
|
35
36
|
([message_type] + params).join("-")
|
36
37
|
end
|
37
38
|
|
@@ -39,12 +40,47 @@ module Strum
|
|
39
40
|
@handlers ||= {}
|
40
41
|
end
|
41
42
|
|
42
|
-
def
|
43
|
-
|
43
|
+
def enable_json(switcher)
|
44
|
+
@json_mode = switcher
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
|
47
|
+
def json_enabled?
|
48
|
+
@json_mode
|
49
|
+
end
|
50
|
+
|
51
|
+
def enable_protobuf(switcher)
|
52
|
+
@protobuf_mode = switcher
|
53
|
+
end
|
54
|
+
|
55
|
+
def protobuf_enabled?
|
56
|
+
@protobuf_mode
|
57
|
+
end
|
58
|
+
|
59
|
+
def content_type_enabled?(content_type)
|
60
|
+
case content_type
|
61
|
+
when "application/json"
|
62
|
+
json_enabled?
|
63
|
+
when "application/x-protobuf"
|
64
|
+
protobuf_enabled?
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def use_protobuf_service(service)
|
71
|
+
raise ArgumentError, "#{service} must be a grpc service" unless service.respond_to?(:rpc_descs)
|
72
|
+
|
73
|
+
@protobuf_service = service
|
74
|
+
enable_protobuf(true)
|
75
|
+
end
|
76
|
+
|
77
|
+
def protobuf_service
|
78
|
+
@protobuf_service
|
79
|
+
end
|
80
|
+
|
81
|
+
def use_application_config
|
82
|
+
enable_json(Strum::Esb.config.enable_json)
|
83
|
+
enable_protobuf(Strum::Esb.config.enable_protobuf)
|
48
84
|
end
|
49
85
|
end
|
50
86
|
|
@@ -85,12 +121,14 @@ module Strum
|
|
85
121
|
|
86
122
|
content_type = metadata[:content_type] || "application/json"
|
87
123
|
|
88
|
-
unless
|
124
|
+
unless self.class.content_type_enabled?(content_type)
|
89
125
|
logger.error "Content type #{content_type} is disabled by handler. Message rejected #{metadata[:headers]} with payload #{deserialized_msg}"
|
90
126
|
return reject!
|
91
127
|
end
|
92
128
|
|
93
|
-
|
129
|
+
args = { queue_method_name: method_name, grpc_service: self.class.protobuf_service, content_type: content_type }
|
130
|
+
|
131
|
+
payload, valid_payload = Strum::Esb.config.serializer.deserialize(deserialized_msg, args: args)
|
94
132
|
|
95
133
|
unless valid_payload
|
96
134
|
logger.error "Payload was unable to be parsed with #{content_type} content type. Message rejected #{metadata[:headers]} with payload #{payload}"
|
@@ -100,9 +138,12 @@ module Strum
|
|
100
138
|
error = nil
|
101
139
|
method_params = method(method_name)
|
102
140
|
.parameters
|
103
|
-
.map
|
141
|
+
.map do |param|
|
142
|
+
_, param_name = param
|
143
|
+
param_name
|
144
|
+
end
|
104
145
|
.then { |m| m & %I[action resource event state info pipeline pipeline_id] }
|
105
|
-
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) }
|
106
147
|
logger.info("Handler #{method_name} found. Payload: #{payload}")
|
107
148
|
handler_params.count.positive? ? send(method_name, payload, handler_params) : send(method_name, payload)
|
108
149
|
logger.info("Handler #{method_name} executed")
|
@@ -153,7 +194,7 @@ module Strum
|
|
153
194
|
result << "notice_#{notice}"
|
154
195
|
result << "notice_handler"
|
155
196
|
result
|
156
|
-
end
|
197
|
+
end
|
157
198
|
end
|
158
199
|
end
|
159
200
|
end
|
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:,
|
9
|
-
|
10
|
-
|
10
|
+
def publish(exchange:, headers:, payload:, exchange_options: {}, **args)
|
11
|
+
new(
|
12
|
+
exchange: exchange,
|
11
13
|
headers: headers,
|
12
|
-
|
13
|
-
|
14
|
+
payload: payload,
|
15
|
+
exchange_options: exchange_options,
|
16
|
+
**args
|
17
|
+
).publish
|
18
|
+
end
|
19
|
+
end
|
14
20
|
|
15
|
-
|
21
|
+
attr_reader :exchange,
|
22
|
+
:headers,
|
23
|
+
:payload,
|
24
|
+
:args,
|
25
|
+
:exchange_options,
|
26
|
+
:rabbit_channel
|
16
27
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
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
|
26
42
|
|
27
|
-
|
28
|
-
|
43
|
+
rabbit_exchange.publish(payload, **properties)
|
44
|
+
end
|
45
|
+
|
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
@@ -7,28 +7,20 @@ module Strum
|
|
7
7
|
CONTENT_TYPES = %w[application/json application/x-protobuf].freeze
|
8
8
|
|
9
9
|
%i[serialize deserialize].each do |base_method|
|
10
|
-
define_method base_method do |payload,
|
11
|
-
|
10
|
+
define_method base_method do |payload, args: {}|
|
11
|
+
content_type = args.fetch(:content_type)
|
12
|
+
raise ArgumentError, "invalid content_type" unless valid_content_type?(content_type)
|
12
13
|
|
13
14
|
perform_method_name = content_type_method_name(base_method, content_type)
|
14
|
-
payload = send(
|
15
|
+
payload = send(perform_method_name, payload, args: args)
|
15
16
|
[payload, true]
|
16
|
-
rescue StandardError
|
17
|
+
rescue StandardError => e
|
18
|
+
Sneakers.logger.error(e.inspect)
|
19
|
+
Sneakers.logger.error "Content type is invalid. Message rejected #{args[:headers]} with payload #{payload}"
|
17
20
|
[payload, false]
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
def enabled?(content_type)
|
22
|
-
case data_type(content_type)
|
23
|
-
when "json"
|
24
|
-
Strum::Esb.config.json
|
25
|
-
when "protobuf"
|
26
|
-
Strum::Esb.config.protobuf_service
|
27
|
-
else
|
28
|
-
false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
24
|
private
|
33
25
|
|
34
26
|
def valid_content_type?(content_type)
|
@@ -43,22 +35,26 @@ module Strum
|
|
43
35
|
content_type.gsub("-", "/").split("/").last
|
44
36
|
end
|
45
37
|
|
46
|
-
def deserialize_json(payload,
|
38
|
+
def deserialize_json(payload, args: {}) # rubocop:disable Lint/UnusedMethodArgument
|
47
39
|
JSON.parse(payload)
|
48
40
|
end
|
49
41
|
|
50
|
-
def deserialize_protobuf(payload,
|
51
|
-
action_name = inflector.camelize(queue_method_name)
|
52
|
-
|
53
|
-
|
42
|
+
def deserialize_protobuf(payload, args: {})
|
43
|
+
action_name = inflector.camelize(args.fetch(:queue_method_name))
|
44
|
+
message_class = args.fetch(:grpc_service).rpc_descs[action_name.to_sym].input
|
45
|
+
|
46
|
+
Strum::Esb.config.serializer_conf[:from_proto].call(message_class, payload)
|
54
47
|
end
|
55
48
|
|
56
|
-
def serialize_json(payload)
|
49
|
+
def serialize_json(payload, args: {}) # rubocop:disable Lint/UnusedMethodArgument
|
57
50
|
payload.to_json
|
58
51
|
end
|
59
52
|
|
60
|
-
def serialize_protobuf(payload)
|
61
|
-
payload
|
53
|
+
def serialize_protobuf(payload, args: {})
|
54
|
+
return payload unless args.key?(:message_class)
|
55
|
+
|
56
|
+
message_class = args.fetch(:message_class)
|
57
|
+
Strum::Esb.config.serializer_conf[:to_proto].call(message_class, payload)
|
62
58
|
end
|
63
59
|
|
64
60
|
def inflector
|
data/lib/strum/esb/version.rb
CHANGED
data/lib/strum/esb.rb
CHANGED
@@ -29,20 +29,29 @@ 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, []
|
41
41
|
setting :before_handler_hooks, []
|
42
42
|
setting :after_handler_hooks, []
|
43
|
+
|
43
44
|
setting :serializer, Serializer.new
|
44
|
-
setting :
|
45
|
-
setting :
|
45
|
+
setting :enable_json, true
|
46
|
+
setting :enable_protobuf, false
|
47
|
+
setting :serializer_conf, {
|
48
|
+
to_proto: proc do |message_class, payload|
|
49
|
+
message_class.new(payload).to_proto
|
50
|
+
end,
|
51
|
+
from_proto: proc do |message_class, encoded_payload|
|
52
|
+
message_class.decode(encoded_payload)
|
53
|
+
end
|
54
|
+
}
|
46
55
|
|
47
56
|
Strum::Esb.config.before_fork_hooks << proc { DB.disconnect } if defined?(DB)
|
48
57
|
|
@@ -56,12 +65,12 @@ module Strum
|
|
56
65
|
@app = app
|
57
66
|
@args = args
|
58
67
|
end
|
59
|
-
|
68
|
+
|
60
69
|
def call(deserialized_msg, delivery_info, metadata, handler)
|
61
|
-
Thread.current.keys.each{ |key| Thread.current[key] = nil }
|
70
|
+
Thread.current.keys.each { |key| Thread.current[key] = nil }
|
62
71
|
@app.call(deserialized_msg, delivery_info, metadata, handler)
|
63
72
|
end
|
64
|
-
end
|
73
|
+
end
|
65
74
|
|
66
75
|
Sneakers.configure(
|
67
76
|
log: $stdout,
|
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
|
+
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
|