jackhammer 1.3.7 → 1.4.0

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: d56a6f3d2a1f7ca03feba155032f34598ac37ebe0a33f909beaf8a4925bb351b
4
- data.tar.gz: 6e2858cc50c7b9139b4b506f64fb9d4c339ac29ce5fbf5b84f8fb42e52c0305c
3
+ metadata.gz: 4aa6bdf41e8005dbbfbcdc2bacfc4fae0a8e182cb35b62fea8d961ba350ef600
4
+ data.tar.gz: 7ce9c945039c1e09b4cec7406c6c1e767f5bc91baf76ace5a9dcdca940f7991b
5
5
  SHA512:
6
- metadata.gz: 02304a35a6234347fac7ea7257b601accada9293c21620569968da7df1f4831d6c36e350c0c5e94872939cce27c43b179fcdaa6fc1b285e4fbef6c8e40e60836
7
- data.tar.gz: 4ea19a99767048e119846b2a024e2c06e060cd79794dda955865d08b7153eebd03c709f63ce0e8c7e050e5b962db45488b8d91113e11a9e2327d33ba71d72dcb
6
+ metadata.gz: e6ace137b8bac8709c3c38cf7fe0109cda7a13e4fe59d4900bb059f9b1403c445eb67419375a9d1c7c438c84d8d55949bb59291f53aa9982f9658364f43a6283
7
+ data.tar.gz: b2d6807b73211b09db3db88bc02de9d2d0509a4451c4b1fc252d92e98eb5b864038c25f3482169fe0325d58b820a5a659c16efea077bf32c668a9fafd2f90ec5
@@ -1,7 +1,7 @@
1
- # automatically approve PRs submitted by Dependabot
1
+ # automatically approve PRs submitted by Dependabot or Renofidev
2
2
  # this will allow Dependabot to automatically merge dependency update PRs where CI passes
3
3
  # from: https://github.com/hmarr/auto-approve-action
4
- name: Auto approve Dependabot PRs
4
+ name: Auto approve dependency upgrades PRs
5
5
 
6
6
  on:
7
7
  pull_request
@@ -11,6 +11,6 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
13
  - uses: hmarr/auto-approve-action@v2.0.0
14
- if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
14
+ if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'renofidev'
15
15
  with:
16
16
  github-token: "${{ secrets.GITHUB_TOKEN }}"
@@ -0,0 +1,29 @@
1
+ name: automerge
2
+ on:
3
+ pull_request:
4
+ types:
5
+ - labeled
6
+ - unlabeled
7
+ - synchronize
8
+ - opened
9
+ - edited
10
+ - ready_for_review
11
+ - reopened
12
+ - unlocked
13
+ pull_request_review:
14
+ types:
15
+ - submitted
16
+ check_suite:
17
+ types:
18
+ - completed
19
+ status: {}
20
+ jobs:
21
+ automerge:
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - name: automerge
25
+ uses: "pascalgn/automerge-action@v0.11.0"
26
+ env:
27
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
28
+ MERGE_METHOD: squash
29
+ MERGE_DELETE_BRANCH: true
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jackhammer (1.3.7)
4
+ jackhammer (1.4.0)
5
5
  bunny (~> 2.14)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.3.2)
11
- activesupport (= 6.0.3.2)
12
- activerecord (6.0.3.2)
13
- activemodel (= 6.0.3.2)
14
- activesupport (= 6.0.3.2)
15
- activesupport (6.0.3.2)
10
+ activemodel (6.0.3.4)
11
+ activesupport (= 6.0.3.4)
12
+ activerecord (6.0.3.4)
13
+ activemodel (= 6.0.3.4)
14
+ activesupport (= 6.0.3.4)
15
+ activesupport (6.0.3.4)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
@@ -20,7 +20,7 @@ GEM
20
20
  zeitwerk (~> 2.2, >= 2.2.2)
21
21
  amq-protocol (2.3.2)
22
22
  ast (2.4.1)
23
- bunny (2.16.1)
23
+ bunny (2.17.0)
24
24
  amq-protocol (~> 2.3, >= 2.3.1)
25
25
  bunny-mock (1.7.0)
26
26
  bunny (>= 1.7)
@@ -31,17 +31,17 @@ GEM
31
31
  concurrent-ruby (~> 1.0)
32
32
  minitest (5.14.2)
33
33
  parallel (1.19.2)
34
- parser (2.7.1.4)
34
+ parser (2.7.2.0)
35
35
  ast (~> 2.4.1)
36
36
  rainbow (3.0.0)
37
37
  rake (13.0.1)
38
- regexp_parser (1.7.1)
38
+ regexp_parser (1.8.2)
39
39
  rexml (3.2.4)
40
40
  rspec (3.9.0)
41
41
  rspec-core (~> 3.9.0)
42
42
  rspec-expectations (~> 3.9.0)
43
43
  rspec-mocks (~> 3.9.0)
44
- rspec-core (3.9.2)
44
+ rspec-core (3.9.3)
45
45
  rspec-support (~> 3.9.3)
46
46
  rspec-expectations (3.9.2)
47
47
  diff-lcs (>= 1.2.0, < 2.0)
@@ -50,19 +50,20 @@ GEM
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.9.0)
52
52
  rspec-support (3.9.3)
53
- rubocop (0.90.0)
53
+ rubocop (0.93.1)
54
54
  parallel (~> 1.10)
55
- parser (>= 2.7.1.1)
55
+ parser (>= 2.7.1.5)
56
56
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.7)
57
+ regexp_parser (>= 1.8)
58
58
  rexml
59
- rubocop-ast (>= 0.3.0, < 1.0)
59
+ rubocop-ast (>= 0.6.0)
60
60
  ruby-progressbar (~> 1.7)
61
61
  unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-ast (0.3.0)
63
- parser (>= 2.7.1.4)
64
- rubocop-performance (1.7.1)
65
- rubocop (>= 0.82.0)
62
+ rubocop-ast (0.7.1)
63
+ parser (>= 2.7.1.5)
64
+ rubocop-performance (1.8.1)
65
+ rubocop (>= 0.87.0)
66
+ rubocop-ast (>= 0.4.0)
66
67
  rubocop-rspec (1.43.2)
67
68
  rubocop (~> 0.87)
68
69
  ruby-progressbar (1.10.1)
data/README.md CHANGED
@@ -90,6 +90,8 @@ module MyApp
90
90
  config.publish_options = { mandatory: true, persistent: true }
91
91
  config.yaml_config = "config/jackhammer.yml"
92
92
  config.app_name = "my_app"
93
+ config.client_middleware.use MyClientMiddleware, some_arg: 1, other_arg: 2
94
+ config.server_middleware.use MyServerMiddleware
93
95
  end
94
96
  end
95
97
  end
@@ -162,10 +164,47 @@ The intent of the options might not be obvious by looking at the name.
162
164
  overridden by passing the same options as arguments in your code).
163
165
  - **yaml_config** defines the file location of the Topic Exchange YAML
164
166
  configuration file.
167
+ - **client_middleware** defines hooks that will be executed prior to publishing a message to a topic
168
+ - **server_middleware** defines hooks that will be executed prior to running the message handler
165
169
 
166
170
  You can find defaults specified in the Jackhammer::Configuration class
167
171
  constructor.
168
172
 
173
+ ### Middleware
174
+
175
+ Middleware allows you to hook into message publishing (client) and handling (server).
176
+
177
+ It can be used to transform the passed in arguments before passing them along or to halt the execution completely.
178
+ The execution will be halted if the middleware instance does not yield.
179
+
180
+ #### Example client middleware
181
+
182
+ ```ruby
183
+ class MyClientMiddleware
184
+ def initialize(name)
185
+ @name = name
186
+ end
187
+
188
+ def call(message, options)
189
+ options[:headers][:hello] = @name
190
+
191
+ yield message, options
192
+ end
193
+ end
194
+ ```
195
+
196
+ #### Example server middleware
197
+
198
+ ```ruby
199
+ class MyServerMiddleware
200
+ def call(handler:, delivery_info:, properties:, content:)
201
+ puts "Hello, #{properties[:headers]['name']}!"
202
+
203
+ yield handler: handler, delivery_info: delivery_info, properties: properties, content: content
204
+ end
205
+ end
206
+ ```
207
+
169
208
  ## Development
170
209
 
171
210
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,6 +7,7 @@ require 'jackhammer/exceptions'
7
7
  require 'jackhammer/log'
8
8
  require 'jackhammer/configuration'
9
9
  require 'jackhammer/message_receiver'
10
+ require 'jackhammer/middleware_collection'
10
11
  require 'jackhammer/queue_name'
11
12
  require 'jackhammer/queue'
12
13
  require 'jackhammer/topic'
@@ -46,5 +47,13 @@ module Jackhammer
46
47
  opts[:headers][:time] ||= time.iso8601
47
48
  end
48
49
  end
50
+
51
+ def client_middleware
52
+ configuration.client_middleware
53
+ end
54
+
55
+ def server_middleware
56
+ configuration.server_middleware
57
+ end
49
58
  end
50
59
  end
@@ -2,6 +2,7 @@ module Jackhammer
2
2
  class Configuration
3
3
  attr_accessor(
4
4
  :app_name,
5
+ :client_middleware,
5
6
  :connection_options,
6
7
  :connection_url,
7
8
  :environment,
@@ -9,6 +10,7 @@ module Jackhammer
9
10
  :logger,
10
11
  :publish_options,
11
12
  :server,
13
+ :server_middleware,
12
14
  :yaml_config
13
15
  )
14
16
 
@@ -20,6 +22,8 @@ module Jackhammer
20
22
  @logger = Logger.new IO::NULL
21
23
  @publish_options = { mandatory: true, persistent: true }
22
24
  @yaml_config = './config/jackhammer.yml'
25
+ @client_middleware = MiddlewareCollection.new
26
+ @server_middleware = MiddlewareCollection.new
23
27
  end
24
28
 
25
29
  def self.instance
@@ -0,0 +1,29 @@
1
+ module Jackhammer
2
+ class MiddlewareCollection
3
+ def initialize
4
+ @entries = []
5
+ end
6
+
7
+ def use(klass, *args, &block)
8
+ @entries << Entry.new(klass: klass, args: args, block: block)
9
+ end
10
+
11
+ def call(*args, &block)
12
+ call_chain = @entries.map(&:instantiate) + [block]
13
+
14
+ traverse = proc do |*arguments|
15
+ call_chain.shift.call(*arguments, &traverse) unless call_chain.empty?
16
+ end
17
+
18
+ traverse.call(*args)
19
+ end
20
+
21
+ Entry = Struct.new(:klass, :args, :block, keyword_init: true) do
22
+ def instantiate
23
+ return klass unless klass.respond_to?(:new)
24
+
25
+ klass.new(*args, &block)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -13,7 +13,15 @@ module Jackhammer
13
13
  queue.subscribe do |delivery_info, properties, content|
14
14
  Log.info { [delivery_info.inspect, properties.inspect].join(' || ') }
15
15
  Log.debug { content }
16
- handler_object.call content
16
+
17
+ Jackhammer.server_middleware.call(
18
+ handler: handler_object,
19
+ delivery_info: delivery_info,
20
+ properties: properties,
21
+ content: content
22
+ ) do |**args|
23
+ args.fetch(:handler).call args.fetch(:content)
24
+ end
17
25
  rescue StandardError => e
18
26
  Log.error e
19
27
  Jackhammer.configuration.exception_adapter.call e
@@ -15,7 +15,9 @@ module Jackhammer
15
15
  # We're expecting the client to specify at least the routing_key in options
16
16
  # for each message published.
17
17
  def publish(message, options)
18
- topic.publish message, Jackhammer.publish_options(options)
18
+ Jackhammer.client_middleware.call(message, Jackhammer.publish_options(options)) do |msg, opts|
19
+ topic.publish msg, opts
20
+ end
19
21
  end
20
22
 
21
23
  def queues
@@ -1,3 +1,3 @@
1
1
  module Jackhammer
2
- VERSION = '1.3.7'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackhammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Serok
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - scott@renofi.com
156
156
  executables:
@@ -164,6 +164,7 @@ files:
164
164
  - ".github/ISSUE_TEMPLATE/story.md"
165
165
  - ".github/PULL_REQUEST_TEMPLATE.md"
166
166
  - ".github/workflows/auto-approve.yml"
167
+ - ".github/workflows/auto-merge.yml"
167
168
  - ".gitignore"
168
169
  - ".rspec"
169
170
  - ".travis.yml"
@@ -181,6 +182,7 @@ files:
181
182
  - lib/jackhammer/exceptions.rb
182
183
  - lib/jackhammer/log.rb
183
184
  - lib/jackhammer/message_receiver.rb
185
+ - lib/jackhammer/middleware_collection.rb
184
186
  - lib/jackhammer/queue.rb
185
187
  - lib/jackhammer/queue_name.rb
186
188
  - lib/jackhammer/rake_task.rb
@@ -194,7 +196,7 @@ licenses:
194
196
  metadata:
195
197
  homepage_uri: https://github.com/renofi/jackhammer
196
198
  source_code_uri: https://github.com/renofi/jackhammer
197
- post_install_message:
199
+ post_install_message:
198
200
  rdoc_options: []
199
201
  require_paths:
200
202
  - lib
@@ -209,8 +211,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
211
  - !ruby/object:Gem::Version
210
212
  version: '0'
211
213
  requirements: []
212
- rubygems_version: 3.1.2
213
- signing_key:
214
+ rubygems_version: 3.1.4
215
+ signing_key:
214
216
  specification_version: 4
215
217
  summary: Jackhammer is an opinionated facade over RabbitMQ Bunny
216
218
  test_files: []