hermes-rb 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b5ec616c41ef3873871546b7943b35a4fc48a0b27503140469a62b4267cf338
4
- data.tar.gz: b387a1d8c2fb8af348c3b35ca5b1642a305eb2fc8a6f7eb4850b90e23f60b873
3
+ metadata.gz: 61eb45c503cb8431d679fd198af4b65f379fd3efe4d40381ae72baf39bffa9bc
4
+ data.tar.gz: '09cf809349943da3991e64e9ceea38b3e9a54cd5d992a6aeb11524c784bbe837'
5
5
  SHA512:
6
- metadata.gz: 1c17d4b5ada3daf1af7e0b17c1c7443d2810797341631090c488a8f397881507cc99504a5f25a93e7e5e65c64db795153e1ea471bbd0e5123a5ef7922e503d04
7
- data.tar.gz: b28b39d8e03b717c4f7b33f20a92efd452c56fa0749716a5b64f6b2b5d7bf8123c62432ac47f96849a4c72e80867a2b79b9c81f4431abfdef5021dd17da43359
6
+ metadata.gz: 67a2991af401ec5a66b2717b683b82ad4816fd6a9bb6be17a688ee19de05bf112c511b81b126cdb224c219b42720125ff59acfd95b865a2fbde908f4f59338ef
7
+ data.tar.gz: f7104301bfc8993a15cade245ec42d2a1a40e308c04033004caa1883aba238908358d6f62bca024c250a6208d20c4d5116db3b1553068c59895db9ce34fa60eb
data/Changelog.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 0.4.0
6
+ - Make it possible to provide Hutch consumer config
7
+
5
8
  ## 0.3.1
6
9
  - Fix filtering params for logs for nil values in sensitive attributes
7
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hermes-rb (0.3.1)
4
+ hermes-rb (0.4.0)
5
5
  activerecord (>= 5)
6
6
  activesupport (>= 5)
7
7
  dry-container (~> 0)
data/README.md CHANGED
@@ -45,8 +45,15 @@ Rails.application.config.to_prepare do
45
45
 
46
46
  event_handler.handle_events do
47
47
  handle Events::Example::Happened, with: Example::HappenedHandler
48
-
49
48
  handle Events::Example::SyncCallHappened, with: Example::SyncCallHappenedHandler, async: false
49
+
50
+ extra_consumer_config = -> do
51
+ classic_queue
52
+ quorum_queue initial_group_size: 3
53
+ arguments "x-max-length" => 10
54
+ end
55
+ handle Events::Example::SomethingHappenedWithExtraConsumerConfig, with: Example::SomethingHappenedWithExtraConsumerConfigHandler,
56
+ consumer_config: extra_consumer_config
50
57
  end
51
58
 
52
59
  # if you care about distributed tracing
@@ -79,7 +86,7 @@ end
79
86
 
80
87
  If you know what you are doing, you don't necessarily have to process things in the background. As long as the class implements the expected interface, you can do anything you want.
81
88
 
82
- 5. `event_handler` - an instance of event handler/storage, just use what is shown in the example.
89
+ 5. `event_handler` - an instance of event handler/storage, just use what is shown in the example. Notice that you can also pass extra consumer config lambda that will be evaluated within the context of Hutch consumer.
83
90
  6. `clock` - a clock object that is time-zone aware, implementing `now` method.
84
91
  7. `configure_hutch` - a way to configure Hutch:
85
92
  - `uri` - the URI for RabbitMQ, required.
@@ -2,7 +2,7 @@ require "hutch"
2
2
 
3
3
  module Hermes
4
4
  class ConsumerBuilder
5
- def build(event_class)
5
+ def build(event_class, consumer_config: -> {})
6
6
  queue = queue_name_from_event(event_class)
7
7
  routing_key = event_class.routing_key
8
8
  consumer_name = consumer_name_from_event(event_class)
@@ -12,6 +12,7 @@ module Hermes
12
12
 
13
13
  consume routing_key
14
14
  queue_name queue
15
+ instance_exec(&consumer_config)
15
16
 
16
17
  define_method :process do |message|
17
18
  instrumenter.instrument("Hermes.Consumer.process") do
@@ -84,5 +84,9 @@ module Hermes
84
84
  def self.objects_resolver
85
85
  Object
86
86
  end
87
+
88
+ def self.consumer_builder
89
+ Hermes::ConsumerBuilder.new
90
+ end
87
91
  end
88
92
  end
@@ -5,25 +5,27 @@ module Hermes
5
5
  attr_reader :container, :consumer_builder
6
6
  private :container, :consumer_builder
7
7
 
8
- def initialize
9
- @container = Dry::Container.new
10
- @consumer_builder = Hermes::ConsumerBuilder.new
8
+ def initialize(container: Dry::Container.new, consumer_builder: Hermes::DependenciesContainer["consumer_builder"])
9
+ @container = container
10
+ @consumer_builder = consumer_builder
11
11
  end
12
12
 
13
13
  def handle_events(&block)
14
14
  instance_exec(&block)
15
15
  end
16
16
 
17
- def handle(event_class, with:, async: true, rpc: false)
17
+ def handle(event_class, with:, async: true, rpc: false, consumer_config: -> {})
18
18
  handler = with
19
19
  options = {
20
20
  async: async,
21
- rpc: rpc
21
+ rpc: rpc,
22
+ consumer_config: consumer_config
22
23
  }
23
- consumer = build_consumer_for_event(event_class)
24
+ consumer = build_consumer_for_event(event_class, consumer_config)
24
25
 
25
- registration = Registration.new(handler, consumer, options)
26
- container.register(event_class, registration)
26
+ Registration.new(handler, consumer, options).tap do |registration|
27
+ container.register(event_class, registration)
28
+ end
27
29
  end
28
30
 
29
31
  def registration_for(event_class)
@@ -32,8 +34,8 @@ module Hermes
32
34
 
33
35
  private
34
36
 
35
- def build_consumer_for_event(event_class)
36
- consumer_builder.build(event_class)
37
+ def build_consumer_for_event(event_class, consumer_config)
38
+ consumer_builder.build(event_class, consumer_config: consumer_config)
37
39
  end
38
40
 
39
41
  class Registration
@@ -52,6 +54,10 @@ module Hermes
52
54
  def rpc?
53
55
  options.fetch(:rpc) == true
54
56
  end
57
+
58
+ def consumer_config
59
+ optons.fetch(:consumer_config)
60
+ end
55
61
  end
56
62
  end
57
63
  end
@@ -1,5 +1,5 @@
1
1
  module Hermes
2
2
  module Rb
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermes-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Galanciak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct