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 +4 -4
- data/Changelog.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -2
- data/lib/hermes/consumer_builder.rb +2 -1
- data/lib/hermes/dependencies_container.rb +4 -0
- data/lib/hermes/event_handler.rb +16 -10
- data/lib/hermes/rb/version.rb +1 -1
- 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: 61eb45c503cb8431d679fd198af4b65f379fd3efe4d40381ae72baf39bffa9bc
|
4
|
+
data.tar.gz: '09cf809349943da3991e64e9ceea38b3e9a54cd5d992a6aeb11524c784bbe837'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a2991af401ec5a66b2717b683b82ad4816fd6a9bb6be17a688ee19de05bf112c511b81b126cdb224c219b42720125ff59acfd95b865a2fbde908f4f59338ef
|
7
|
+
data.tar.gz: f7104301bfc8993a15cade245ec42d2a1a40e308c04033004caa1883aba238908358d6f62bca024c250a6208d20c4d5116db3b1553068c59895db9ce34fa60eb
|
data/Changelog.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
data/lib/hermes/event_handler.rb
CHANGED
@@ -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 =
|
10
|
-
@consumer_builder =
|
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
|
-
|
26
|
-
|
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
|
data/lib/hermes/rb/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|