nexus_domain_events 0.0.0 → 1.1.1
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.rb +1 -0
- data/lib/nexus_domain_events/bus.rb +46 -0
- data/lib/nexus_domain_events/event.rb +1 -1
- data/lib/nexus_domain_events/version.rb +1 -1
- data/nexus_domain_events.gemspec +2 -1
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85b1f0b90f8d665bfa69eb50f7b87223bcdb8d1acd0a582774e57da6fad68a3
|
4
|
+
data.tar.gz: 3bf46a8aaf292b842ce4d54c1944a22d3d2fb6c13be438379f0b2dd3596833c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afbab1103881443f1b25dd691284337ef7b976694268c5eb138f939425024a50c8e8c0cabf0e5fe2ee76de9d8be6f4efbb645f47878d841e07f4c2a3be4fa91e
|
7
|
+
data.tar.gz: 55690f411373b2c7213ca373cbf8cca3b8a218ee0918a914100ee17eeaf6e8ee81823ec2dce90bb1c70e807961cf8228a5a93dc89cbf54fd79c01ae34abc31d8
|
data/lib/nexus_domain_events.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bunny'
|
4
|
+
|
5
|
+
module NexusDomainEvents
|
6
|
+
# A domain events bus for dispatching events to
|
7
|
+
class Bus
|
8
|
+
def initialize(bunny: nil, topic_name: 'domain_events')
|
9
|
+
@mutex = Mutex.new
|
10
|
+
@bunny = bunny
|
11
|
+
@topic_name = topic_name
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Event] domain_event
|
15
|
+
def dispatch(domain_event)
|
16
|
+
ensure_connection!
|
17
|
+
@exchange.publish(
|
18
|
+
domain_event.to_json,
|
19
|
+
routing_key: domain_event.message_name
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
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&.connected? && @channel
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_bunny_connection
|
43
|
+
Bunny.new(ENV['AMQP_CONNECTION'])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/nexus_domain_events.gemspec
CHANGED
@@ -8,7 +8,6 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.email = ['chris.harrison@nexusmods.com']
|
9
9
|
|
10
10
|
spec.summary = 'Ruby based domain eventing tools'
|
11
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
12
11
|
|
13
12
|
# Specify which files should be added to the gem when it is released.
|
14
13
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -17,4 +16,6 @@ Gem::Specification.new do |spec|
|
|
17
16
|
end
|
18
17
|
spec.require_paths = ['lib']
|
19
18
|
spec.add_dependency('activesupport')
|
19
|
+
spec.add_dependency('bunny')
|
20
|
+
spec.add_dependency('bunny-mock')
|
20
21
|
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:
|
4
|
+
version: 1.1.1
|
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
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bunny
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bunny-mock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description:
|
28
56
|
email:
|
29
57
|
- chris.harrison@nexusmods.com
|
@@ -38,6 +66,7 @@ files:
|
|
38
66
|
- Gemfile
|
39
67
|
- README.md
|
40
68
|
- lib/nexus_domain_events.rb
|
69
|
+
- lib/nexus_domain_events/bus.rb
|
41
70
|
- lib/nexus_domain_events/event.rb
|
42
71
|
- lib/nexus_domain_events/version.rb
|
43
72
|
- nexus_domain_events.gemspec
|
@@ -52,14 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
81
|
requirements:
|
53
82
|
- - ">="
|
54
83
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
84
|
+
version: '0'
|
56
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
86
|
requirements:
|
58
87
|
- - ">="
|
59
88
|
- !ruby/object:Gem::Version
|
60
89
|
version: '0'
|
61
90
|
requirements: []
|
62
|
-
rubygems_version: 3.2.
|
91
|
+
rubygems_version: 3.2.10
|
63
92
|
signing_key:
|
64
93
|
specification_version: 4
|
65
94
|
summary: Ruby based domain eventing tools
|