strum-esb 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec01fbb52f6e4bbf0ae78e81b2c6c0d427b6724efc6e8a93283a595a21b512de
4
- data.tar.gz: 57bd11fdbbd47f201d9d962893a160df528ab94c48410904df86c938bdcafc8d
3
+ metadata.gz: 71859024cac83efb0fe65d36972bc59e3a36aa909b8dd01c3a048e1c302c6af2
4
+ data.tar.gz: 3c85a148cdd144bd1f7dab17cece39d33f2dea8ea17813a77353cf4cadbe2ecc
5
5
  SHA512:
6
- metadata.gz: 97c3b7ebbe683fb790b66ac59abf913af645025a72b94cabbd5e0d8c114c8ef3c4cbd7c31b87c1c212e00f07499c807f71e2af1db8265856856693e8649cff9f
7
- data.tar.gz: d7483cb8f561e2b07f11c5cc7a177af1fc9a6b9a01347b5458d76624fff02462d898ed7ec84ba61f8c6aa435814d058b7bd3e99e6dead29d336c4d97734c50ab
6
+ metadata.gz: d94e6c04dc46f018558bb04b1edc16108cab4199e15eaebef3c3520d3e334828150dd524c02ce8005cc8f503207af7ff19c1f6d09ca98462ca0d4889cc4897e9
7
+ data.tar.gz: '09c5454b9283ce7b6c4be64d804bfe8b42894fb52afae00c3296107172cbe3be1841caaed160888b9ba5c3b12d41493b76b4a9fe451d714eaf05f7f7a63fdb47'
data/.gitignore CHANGED
@@ -10,6 +10,9 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
+ .ruby-gemset
14
+ .ruby-version
15
+
13
16
  # Editor directories and files
14
17
  .idea
15
18
  .vscode
data/.rubocop.yml CHANGED
@@ -23,4 +23,14 @@ Style/StringLiterals:
23
23
 
24
24
  Metrics/LineLength:
25
25
  Max: 120
26
- IgnoredPatterns: ['\A#']
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.11.0"
10
- gem "rubocop", "~> 1.36.0"
11
- gem "rubocop-rspec", "~> 2.12.1"
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.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.19.0)
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.1.10)
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.8.1)
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.1.2.1)
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.5)
39
- regexp_parser (2.5.0)
40
+ rbtree (0.4.6)
41
+ regexp_parser (2.7.0)
40
42
  rexml (3.2.5)
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)
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.11.0)
50
- rspec-mocks (3.11.0)
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.11.0)
53
- rspec-support (3.11.0)
54
- rubocop (1.36.0)
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.1.2.1)
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.20.1, < 2.0)
63
+ rubocop-ast (>= 1.28.0, < 2.0)
62
64
  ruby-progressbar (~> 1.7)
63
- unicode-display_width (>= 1.4.0, < 3.0)
64
- rubocop-ast (1.21.0)
65
- parser (>= 3.1.1.0)
66
- rubocop-rspec (2.12.1)
67
- rubocop (~> 1.31)
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.11.0)
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.0)
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.11.0)
95
- rubocop (~> 1.36.0)
96
- rubocop-rspec (~> 2.12.1)
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
@@ -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 = resource_notice.split("/")
21
+ resource, notice = resource_notice.split("/")
22
22
  [exchange, resource, notice]
23
23
  end
24
24
 
@@ -138,9 +138,12 @@ module Strum
138
138
  error = nil
139
139
  method_params = method(method_name)
140
140
  .parameters
141
- .map { |param| _, param_name = param; param_name }
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")
@@ -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
- rabbit_exchange ||= Strum::Esb.config.rabbit_channel_pool.with do |rabbit_channel|
10
- rabbit_channel.headers(exchange, durable: true)
11
- end
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
- properties = { headers: headers, content_type: args.fetch(:content_type, "application/json") }
21
+ attr_reader :exchange,
22
+ :headers,
23
+ :payload,
24
+ :args,
25
+ :exchange_options,
26
+ :rabbit_channel
14
27
 
15
- Strum::Esb.config.before_publish_hooks.each { |hook| hook.call(payload, properties) }
16
- args.merge!(properties)
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
- payload, valid_payload = Strum::Esb.config.serializer.serialize(payload, args: args)
19
- return unless valid_payload
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
- rabbit_exchange.publish(payload, **properties)
22
- end
43
+ rabbit_exchange.publish(payload, **properties)
44
+ end
23
45
 
24
- def extend_headers(properties)
25
- properties[:headers] = {} unless properties[:headers].is_a?(Hash)
26
- properties[:headers]["pipeline"] ||= Thread.current[:pipeline] if Thread.current[:pipeline]
27
- properties[:headers]["pipeline-id"] ||= Thread.current[:pipeline_id] if Thread.current[:pipeline_id]
28
- end
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
@@ -51,6 +51,8 @@ module Strum
51
51
  end
52
52
 
53
53
  def serialize_protobuf(payload, args: {})
54
+ return payload unless args.key?(:message_class)
55
+
54
56
  message_class = args.fetch(:message_class)
55
57
  Strum::Esb.config.serializer_conf[:to_proto].call(message_class, payload)
56
58
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strum
4
4
  module Esb
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
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
- 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
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).to_h
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.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: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny