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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 681696a0e3df1cbcbf54e5b0c1a103893a3cc75bc12bcd402c84eeee2176c7d7
4
- data.tar.gz: 52ea658a2ea2d82d04661009c11592bb06e5ec11fc5732e9c0478c1c57883544
3
+ metadata.gz: f85b1f0b90f8d665bfa69eb50f7b87223bcdb8d1acd0a582774e57da6fad68a3
4
+ data.tar.gz: 3bf46a8aaf292b842ce4d54c1944a22d3d2fb6c13be438379f0b2dd3596833c5
5
5
  SHA512:
6
- metadata.gz: b12d6d112682b360015a7c207d36e34372b001b5044820b73f4435c0a78cffc8e4dbd8920e96de13072fdb20058042b5c7a03ae083ef91f4e22aaf88696c56d8
7
- data.tar.gz: 4d69e591d7dcb24ae53518dd735efa3689853fd9d77577f81e971923fe041fcd08ef34c97551ec69e6699d758c2f89603bebda6761f7c0a9a1052d58225a7037
6
+ metadata.gz: afbab1103881443f1b25dd691284337ef7b976694268c5eb138f939425024a50c8e8c0cabf0e5fe2ee76de9d8be6f4efbb645f47878d841e07f4c2a3be4fa91e
7
+ data.tar.gz: 55690f411373b2c7213ca373cbf8cca3b8a218ee0918a914100ee17eeaf6e8ee81823ec2dce90bb1c70e807961cf8228a5a93dc89cbf54fd79c01ae34abc31d8
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  require 'nexus_domain_events/event'
3
+ require 'nexus_domain_events/bus'
@@ -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
@@ -20,7 +20,7 @@ module NexusDomainEvents
20
20
  message_id: nil,
21
21
  created_at: nil
22
22
  )
23
- @message_name = message_name
23
+ @message_name = message_name.upcase
24
24
  @actor = actor
25
25
  @payload = payload
26
26
  @message_id = message_id || SecureRandom.uuid
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusDomainEvents
3
- VERSION = '0.0.0'
3
+ VERSION = '1.1.1'
4
4
  end
@@ -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: 0.0.0
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-01-28 00:00:00.000000000 Z
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: 2.3.0
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.7
91
+ rubygems_version: 3.2.10
63
92
  signing_key:
64
93
  specification_version: 4
65
94
  summary: Ruby based domain eventing tools