nexus_domain_events 1.0.1 → 1.1.2

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: '09ee1d8a1cf68e5c60d8c25c5207a3d9162cf395e4adfa88d71d0a7dda59fcb6'
4
- data.tar.gz: c767b8c7442f51345e205d4880dfc1f4f2500186a0fa292f098b51c93372f813
3
+ metadata.gz: 531687ab020e0d37c567ec99ef2b5fc2091871524ddde0a080d45d86bcdc0485
4
+ data.tar.gz: 8ea060af971cfd1539f907bde393b1bfdc22f246d0b7ef5799d03001f49595c7
5
5
  SHA512:
6
- metadata.gz: d144b45f1e6bb3abf62d1c99cbbeb906955352c9b283fd28534e4f17e0920f911d92e3f111f8bdc5ab6262651318508879c8fd2b1837a59e7b7b092b21fa3a47
7
- data.tar.gz: 3f7828176eaa5261c9b55e51de4a31281d93a4ab41e8ec60a1c0d0c4f32a7cbf829e7faaeddce4595aaec829ec9433884c66e4803347d8ee849ac40dfd53758e
6
+ metadata.gz: fc8fcc03b7986e7d06f68ea9caba75d1629421eb5def30fd55d4ecff1014f2fbe57ad19f1ca2ed35fd649c2e6139b0b6a7047233ffc8b18b834a7e26fba7b71c
7
+ data.tar.gz: 5b50e1907185dbd55946cc9c6361b1065aac3123acdceba2a1e9904464c9f7a75c66660c0d3a9c8e96533d25af8af05c820a4b04f8bf34e321af03b716788eb6
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ gem 'rubocop'
7
7
  gem 'rubocop-shopify', "~> 1.0.4", require: false
8
8
 
9
9
  gem 'rspec'
10
+
11
+ gem 'bunny-mock'
@@ -1,15 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bunny'
4
+
3
5
  module NexusDomainEvents
4
6
  # A domain events bus for dispatching events to
5
7
  class Bus
6
- def initialize(topic: nil)
7
- @topic = topic || default_topic
8
+ def initialize(bunny: nil, topic_name: 'domain_events')
9
+ @mutex = Mutex.new
10
+ @bunny = bunny
11
+ @topic_name = topic_name
8
12
  end
9
13
 
10
14
  # @param [Event] domain_event
11
15
  def dispatch(domain_event)
12
- @topic.publish(
16
+ ensure_connection!
17
+ @exchange.publish(
13
18
  domain_event.to_json,
14
19
  routing_key: domain_event.message_name
15
20
  )
@@ -17,10 +22,25 @@ module NexusDomainEvents
17
22
 
18
23
  private
19
24
 
20
- def default_topic
21
- conn = Bunny.new(ENV['AMQP_CONNECTION']).start
22
- channel = conn.create_channel
23
- channel.topic('domain_events', durable: true)
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'])
24
44
  end
25
45
  end
26
46
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusDomainEvents
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.2'
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.6.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,5 @@ 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
20
  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.1
4
+ version: 1.1.2
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-29 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,20 @@ 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'
27
41
  description:
28
42
  email:
29
43
  - chris.harrison@nexusmods.com
@@ -53,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - ">="
55
69
  - !ruby/object:Gem::Version
56
- version: 2.6.0
70
+ version: '0'
57
71
  required_rubygems_version: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  requirements: []
63
- rubygems_version: 3.2.7
77
+ rubygems_version: 3.2.10
64
78
  signing_key:
65
79
  specification_version: 4
66
80
  summary: Ruby based domain eventing tools