nexus_domain_events 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexus_domain_events/bus.rb +25 -7
- data/lib/nexus_domain_events/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a036654aa781f96773e136e9e1bc9386d3e7918db25418133c4537db0a063c57
|
4
|
+
data.tar.gz: f6ace35c60cee9d5f07acecabe03948ca87ffc664726b724b6666db21836c8d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa4cc3e36ca93dacb8ad38779690b056391f58656c241d55f790b3544280096f124f8a37d1f84ec614d960a7a7ed83f793112d624df7b887f8a213e26aabc24
|
7
|
+
data.tar.gz: '0439e408f6c19478b25481bd0c4f3c10bfb830132d4c3d50a0295850024066e5ff5050eddc28302110591915919b557b6ea93abfa16877cb0a4fb626e545dad6'
|
@@ -5,13 +5,16 @@ require 'bunny'
|
|
5
5
|
module NexusDomainEvents
|
6
6
|
# A domain events bus for dispatching events to
|
7
7
|
class Bus
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(bunny: nil, topic_name: 'domain_events')
|
9
|
+
@mutex = Mutex.new
|
10
|
+
@bunny = bunny
|
11
|
+
@topic_name = topic_name
|
10
12
|
end
|
11
13
|
|
12
14
|
# @param [Event] domain_event
|
13
15
|
def dispatch(domain_event)
|
14
|
-
|
16
|
+
ensure_connection!
|
17
|
+
@exchange.publish(
|
15
18
|
domain_event.to_json,
|
16
19
|
routing_key: domain_event.message_name
|
17
20
|
)
|
@@ -19,10 +22,25 @@ module NexusDomainEvents
|
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
def ensure_connection!
|
26
|
+
@mutex.synchronize do
|
27
|
+
connect! unless connected?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def connect!
|
32
|
+
@bunny ||= create_bunny_connection
|
33
|
+
@bunny.start
|
34
|
+
@channel = @bunny.create_channel
|
35
|
+
@exchange = @channel.topic(@topic_name, durable: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def connected?
|
39
|
+
@bunny && @bunny.connected? && @channel
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_bunny_connection
|
43
|
+
Bunny.new(ENV['AMQP_CONNECTION'])
|
26
44
|
end
|
27
45
|
end
|
28
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_domain_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Harrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.2.
|
77
|
+
rubygems_version: 3.2.10
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Ruby based domain eventing tools
|