strum-esb 0.1.0 → 0.1.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: 2caca6a995f15c20737aa3ea31ee69be5660b058cf4ab632740225d31797c272
4
- data.tar.gz: 81d1fd921e9e610b8fe65f275200485d2476a0761e205b229c0a09f790c65da7
3
+ metadata.gz: 8ce4f150ec3058cd6296aadaba679e410a53b0b0f50843c0ec1d71f0c8ce5134
4
+ data.tar.gz: cc4a35c95f53aa9fdbc8b7b341aee355c513fab06d4af19240bb454b95d26ad9
5
5
  SHA512:
6
- metadata.gz: 4391409756c8fbc6c346ce9124d72052d849846f9b88eb7f26885d1a1405b66fe21db5129a644811361c6d77a35071b3887cdcb00cce30b68ee6593ed3ea380d
7
- data.tar.gz: 92b3f5be2af199ec1c803cda251667e11206c1eca20d88efdb33bdfc2a72eb5dc8c55760d767aa22be7bba5e453c631b47f087825cf6426f38043f0a3cedb38c
6
+ metadata.gz: 804f610986a6b13f1948a3a4fea93fb53733c0693c7301a19fb0eba8ede1ed7d05549f7d3bd4d889264f5346c48bac7299597fd1aab740e3dfe5189750cd741b
7
+ data.tar.gz: 38cce564ca77e76433efdda7bea1b5566712c87f3d9abfba0debe102fe2933809afd0ecf6e3c71fbe7870d99383f4fc6ca3972234e0522036829a3e20eed827b
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+
2
+ # Changelog
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.1] - 2021-06-01
6
+ ### Added
7
+ - `pre_publish_hooks` to configuration by [@Samuron]
8
+
9
+ ### Fixed
10
+ - bindings for `notice` by [@anton.klyzhka].
11
+ - custom handlers for resource name with `-` by [@anton.klyzhka].
12
+
13
+ ### Changed
14
+ - return `chain` to header and payload for back compatibility by [@anton.klyzhka].
data/Gemfile CHANGED
@@ -7,9 +7,8 @@ gemspec
7
7
 
8
8
  gem "bundler", "~> 2.1.4"
9
9
  gem "rspec", "~> 3"
10
- gem "rubocop", "~> 0.90.0"
10
+ gem "rubocop", "~> 1.15"
11
11
 
12
12
  gem "debase", "~> 0.2.4"
13
13
  gem "ruby-debug-ide", "~> 0.7.2"
14
14
 
15
- gem "dry-configurable", "~> 0.11"
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strum-esb (0.1.0)
4
+ strum-esb (0.1.1)
5
5
  bunny (~> 2.15)
6
6
  connection_pool (~> 2.2.2)
7
+ dry-configurable (~> 0.12)
7
8
  json (~> 2.3)
8
9
  sneakers (~> 2.12)
9
10
 
@@ -11,59 +12,60 @@ GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
14
  amq-protocol (2.3.2)
14
- ast (2.4.1)
15
- bunny (2.17.0)
15
+ ast (2.4.2)
16
+ bunny (2.18.0)
16
17
  amq-protocol (~> 2.3, >= 2.3.1)
17
- concurrent-ruby (1.1.7)
18
+ sorted_set (~> 1, >= 1.0.2)
19
+ concurrent-ruby (1.1.8)
18
20
  connection_pool (2.2.5)
19
21
  debase (0.2.4.1)
20
22
  debase-ruby_core_source (>= 0.10.2)
21
- debase-ruby_core_source (0.10.11)
23
+ debase-ruby_core_source (0.10.12)
22
24
  diff-lcs (1.4.4)
23
- dry-configurable (0.11.6)
25
+ dry-configurable (0.12.1)
24
26
  concurrent-ruby (~> 1.0)
25
- dry-core (~> 0.4, >= 0.4.7)
26
- dry-equalizer (~> 0.2)
27
+ dry-core (~> 0.5, >= 0.5.0)
27
28
  dry-core (0.5.0)
28
29
  concurrent-ruby (~> 1.0)
29
- dry-equalizer (0.3.0)
30
30
  json (2.5.1)
31
31
  parallel (1.20.1)
32
- parser (2.7.2.0)
32
+ parser (3.0.1.1)
33
33
  ast (~> 2.4.1)
34
34
  rainbow (3.0.0)
35
35
  rake (12.3.3)
36
- regexp_parser (2.0.0)
37
- rexml (3.2.4)
36
+ rbtree (0.4.4)
37
+ regexp_parser (2.1.1)
38
+ rexml (3.2.5)
38
39
  rspec (3.10.0)
39
40
  rspec-core (~> 3.10.0)
40
41
  rspec-expectations (~> 3.10.0)
41
42
  rspec-mocks (~> 3.10.0)
42
- rspec-core (3.10.0)
43
+ rspec-core (3.10.1)
43
44
  rspec-support (~> 3.10.0)
44
- rspec-expectations (3.10.0)
45
+ rspec-expectations (3.10.1)
45
46
  diff-lcs (>= 1.2.0, < 2.0)
46
47
  rspec-support (~> 3.10.0)
47
- rspec-mocks (3.10.0)
48
+ rspec-mocks (3.10.2)
48
49
  diff-lcs (>= 1.2.0, < 2.0)
49
50
  rspec-support (~> 3.10.0)
50
- rspec-support (3.10.0)
51
- rubocop (0.90.0)
51
+ rspec-support (3.10.2)
52
+ rubocop (1.15.0)
52
53
  parallel (~> 1.10)
53
- parser (>= 2.7.1.1)
54
+ parser (>= 3.0.0.0)
54
55
  rainbow (>= 2.2.2, < 4.0)
55
- regexp_parser (>= 1.7)
56
+ regexp_parser (>= 1.8, < 3.0)
56
57
  rexml
57
- rubocop-ast (>= 0.3.0, < 1.0)
58
+ rubocop-ast (>= 1.5.0, < 2.0)
58
59
  ruby-progressbar (~> 1.7)
59
- unicode-display_width (>= 1.4.0, < 2.0)
60
- rubocop-ast (0.8.0)
61
- parser (>= 2.7.1.5)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.6.0)
62
+ parser (>= 3.0.1.1)
62
63
  ruby-debug-ide (0.7.2)
63
64
  rake (>= 0.8.1)
64
- ruby-progressbar (1.10.1)
65
+ ruby-progressbar (1.11.0)
65
66
  serverengine (2.1.1)
66
67
  sigdump (~> 0.2.2)
68
+ set (1.0.1)
67
69
  sigdump (0.2.4)
68
70
  sneakers (2.12.0)
69
71
  bunny (~> 2.14)
@@ -71,8 +73,11 @@ GEM
71
73
  rake (~> 12.3)
72
74
  serverengine (~> 2.1.0)
73
75
  thor
76
+ sorted_set (1.0.3)
77
+ rbtree
78
+ set (~> 1.0)
74
79
  thor (1.1.0)
75
- unicode-display_width (1.7.0)
80
+ unicode-display_width (2.0.0)
76
81
 
77
82
  PLATFORMS
78
83
  ruby
@@ -80,9 +85,8 @@ PLATFORMS
80
85
  DEPENDENCIES
81
86
  bundler (~> 2.1.4)
82
87
  debase (~> 0.2.4)
83
- dry-configurable (~> 0.11)
84
88
  rspec (~> 3)
85
- rubocop (~> 0.90.0)
89
+ rubocop (~> 1.15)
86
90
  ruby-debug-ide (~> 0.7.2)
87
91
  strum-esb!
88
92
 
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ####Configuration
23
+ ### Configuration
24
24
 
25
25
  Exchanges can be customized by each message type:
26
26
  ```ruby
@@ -30,7 +30,12 @@ Strum::Esb.config.action_exchange = `demo.actions`
30
30
  Strum::Esb.config.notice_exchange = `demo.notice`
31
31
  ```
32
32
 
33
- ####Sending message:
33
+ Pre publish hooks allow you to configure custom code that will be able to modify properties of the message that will be published or execute any arbitrary logic
34
+ ```ruby
35
+ Strum::Esb.config.pre_publish_hooks << ->(body, properties) { properties[:correlation_id] = "hello world" }
36
+ ```
37
+
38
+ ### Sending message:
34
39
 
35
40
  ```ruby
36
41
  Strum::Esb::Action.call(`payload`, `action`, `resource`)
@@ -50,7 +55,7 @@ Strum::Esb::Notice.call(`payload`, `notice`)
50
55
  Strum::Esb::Notice.call(`payload`, `notice`, `resource`)
51
56
  ```
52
57
 
53
- #### Handling message:
58
+ ### Handling message:
54
59
 
55
60
  ```ruby
56
61
  require "strum/esb"
data/lib/strum/esb.rb CHANGED
@@ -34,6 +34,7 @@ module Strum
34
34
  end
35
35
  setting :before_fork_hooks, []
36
36
  setting :after_fork_hooks, []
37
+ setting :pre_publish_hooks, []
37
38
 
38
39
  Strum::Esb.config.before_fork_hooks << proc { DB.disconnect } if defined?(DB)
39
40
 
@@ -5,8 +5,8 @@ module Strum
5
5
  class Functions
6
6
  class << self
7
7
  def action_explain(source)
8
- exchange, resource_event = source.include?(":") ? source.split(":") : [Strum::Esb.config.action_exchange, source]
9
- action, resource = resource_event.split("/")
8
+ exchange, resource_action = source.include?(":") ? source.split(":") : [Strum::Esb.config.action_exchange, source]
9
+ action, resource = resource_action.split("/")
10
10
  [exchange, action, resource]
11
11
  end
12
12
 
@@ -17,7 +17,9 @@ module Strum
17
17
  end
18
18
 
19
19
  def notice_explain(source)
20
- source.include?(":") ? source.split(":") : [Strum::Esb.config.notice_exchange, source]
20
+ exchange, resource_notice = source.include?(":") ? source.split(":") : [Strum::Esb.config.notice_exchange, source]
21
+ resource, notice = resource_notice.split("/")
22
+ [exchange, resource, notice]
21
23
  end
22
24
 
23
25
  def info_explain(source)
@@ -22,12 +22,13 @@ module Strum
22
22
  from_queue queue, bindings: bindings
23
23
  _, *msg = Strum::Esb::Functions.public_send("#{message_type}_explain", message_binding)
24
24
  @handlers ||= {}
25
- handler_key = ([message_type] + msg).join("-")
25
+ params = msg.map{ |param| param&.to_s.gsub(/[^a-zA-Z0-9]/, "_")&.downcase }
26
+ handler_key = ([message_type] + params).join("-")
26
27
  @handlers[handler_key] = handler.to_s if handler
27
28
  end
28
29
 
29
30
  def handlers
30
- @handlers
31
+ @handlers || {}
31
32
  end
32
33
  end
33
34
 
@@ -44,6 +45,7 @@ module Strum
44
45
  state = header.call("state")
45
46
  info = header.call("info")
46
47
  notice = header.call("notice")
48
+ Thread.current[:chain] = header.call("chain")
47
49
  Thread.current[:pipeline] = header.call("pipeline")
48
50
  Thread.current[:pipeline_id] = header.call("pipeline-id")
49
51
 
@@ -62,18 +64,18 @@ module Strum
62
64
  method_name = ([*methods_names] << "handler").find { |n| respond_to?(n, include_all: true) }
63
65
 
64
66
  unless method_name
65
- logger.debug "Handler not found. Message rejected #{metadata[:headers]} with payload #{notice_data}"
67
+ logger.error "Handler not found. Message rejected #{metadata[:headers]} with payload #{notice_data}"
66
68
  return reject!
67
69
  end
68
70
 
69
71
  method_params = method(method_name)
70
72
  .parameters
71
73
  .map { |param| _, param_name = param; param_name }
72
- .then { |m| m & %I[action resource event state info] }
74
+ .then { |m| m & %I[action resource event state info chain] }
73
75
  handler_params = method_params.each_with_object({}) { |i, res| res[i] = eval(i.to_s); }
74
- logger.debug("Handler #{method_name} found. Payload: #{notice_data}")
76
+ logger.info("Handler #{method_name} found. Payload: #{notice_data}")
75
77
  handler_params.count.positive? ? send(method_name, notice_data, handler_params) : send(method_name, notice_data)
76
- logger.debug("Handler #{method_name} executed")
78
+ logger.info("Handler #{method_name} executed")
77
79
  ack!
78
80
  rescue StandardError => e
79
81
  logger.error e
@@ -7,9 +7,24 @@ module Strum
7
7
  class << self
8
8
  def publish(exchange:, headers:, payload:)
9
9
  rabbit_exchange ||= Strum::Esb.config.rabbit_channel_pool.with { |rabbit_channel| rabbit_channel.headers(exchange, durable: true) }
10
- headers["pipeline"] ||= Thread.current[:pipeline] if Thread.current[:pipeline]
11
- headers["pipeline-id"] ||= Thread.current[:pipeline_id] if Thread.current[:pipeline_id]
12
- rabbit_exchange.publish(payload.to_json, headers: headers, content_type: "application/json")
10
+ properties = {
11
+ headers: headers,
12
+ content_type: "application/json"
13
+ }
14
+
15
+ Strum::Esb.config.pre_publish_hooks.each do |hook|
16
+ hook.call(payload, properties)
17
+ end
18
+
19
+ properties[:headers] = {} unless properties[:headers].is_a?(Hash)
20
+ properties[:headers]["pipeline"] ||= Thread.current[:pipeline] if Thread.current[:pipeline]
21
+ properties[:headers]["pipeline-id"] ||= Thread.current[:pipeline_id] if Thread.current[:pipeline_id]
22
+ if chain = Thread.current[:chain]
23
+ payload["chain"] ||= chain
24
+ headers["chain"] ||= chain
25
+ end
26
+
27
+ rabbit_exchange.publish(payload.to_json, **properties)
13
28
  end
14
29
  end
15
30
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strum
4
4
  module Esb
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -92,13 +92,14 @@ module QueuePatch
92
92
 
93
93
  def notices_subscribes(notices, **custom_headers)
94
94
  notices.each do |_info|
95
- exchange, resource = Strum::Esb::Functions.info_explain(_info)
95
+ exchange, resource, notice = Strum::Esb::Functions.notice_explain(_info)
96
96
  raise StandardError "notice binding format must be a `exchange:resource`" unless resource
97
97
 
98
98
  @opts[:header_bindings] << {
99
99
  exchange: exchange,
100
100
  arguments: {
101
- notice: resource
101
+ notice: notice,
102
+ resource: resource
102
103
  }.merge(custom_headers)
103
104
  }
104
105
  end
data/strum-esb.gemspec CHANGED
@@ -10,14 +10,14 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "Publish and subscribe rabbitMQ messages"
12
12
  spec.description = "Publish and subscribe rabbitMQ messages"
13
- spec.homepage = "https://code.qpard.com/strum/strum-esb"
13
+ spec.homepage = "https://gitlab.com/strum-rb/strum-esb"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://code.qpard.com/strum/strum-esb"
20
- spec.metadata["changelog_uri"] = "https://code.qpard.com/strum/strum-esb/CHANGELOG.md"
19
+ spec.metadata["source_code_uri"] = "https://gitlab.com/strum-rb/strum-esb"
20
+ spec.metadata["changelog_uri"] = "https://gitlab.com/strum-rb/strum-esb/CHANGELOG.md"
21
21
 
22
22
  # Specify which files should be added to the gem when it is released.
23
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "connection_pool", "~> 2.2.2"
33
33
  spec.add_dependency "json", "~> 2.3"
34
34
  spec.add_dependency "sneakers", "~> 2.12"
35
+ spec.add_dependency "dry-configurable", "~> 0.12"
35
36
  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.1.0
4
+ version: 0.1.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: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dry-configurable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
69
83
  description: Publish and subscribe rabbitMQ messages
70
84
  email:
71
85
  - sn@nazarov.com.ua
@@ -78,6 +92,7 @@ files:
78
92
  - ".rspec"
79
93
  - ".rubocop.yml"
80
94
  - ".travis.yml"
95
+ - CHANGELOG.md
81
96
  - Gemfile
82
97
  - Gemfile.lock
83
98
  - README.md
@@ -95,13 +110,13 @@ files:
95
110
  - lib/strum/esb/version.rb
96
111
  - lib/strum/patch/sneakers/queue_patch.rb
97
112
  - strum-esb.gemspec
98
- homepage: https://code.qpard.com/strum/strum-esb
113
+ homepage: https://gitlab.com/strum-rb/strum-esb
99
114
  licenses: []
100
115
  metadata:
101
116
  allowed_push_host: https://rubygems.org
102
- homepage_uri: https://code.qpard.com/strum/strum-esb
103
- source_code_uri: https://code.qpard.com/strum/strum-esb
104
- changelog_uri: https://code.qpard.com/strum/strum-esb/CHANGELOG.md
117
+ homepage_uri: https://gitlab.com/strum-rb/strum-esb
118
+ source_code_uri: https://gitlab.com/strum-rb/strum-esb
119
+ changelog_uri: https://gitlab.com/strum-rb/strum-esb/CHANGELOG.md
105
120
  post_install_message:
106
121
  rdoc_options: []
107
122
  require_paths: