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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30b0fbf9d8b8be74dd29f1b355a9cfb3ed65ad13379b2568b5ceb9647378ff28
4
- data.tar.gz: fb545d30fd17a92252d259b27c106399ce21e9d2d939d8049ea5f878cf7dadf0
3
+ metadata.gz: a036654aa781f96773e136e9e1bc9386d3e7918db25418133c4537db0a063c57
4
+ data.tar.gz: f6ace35c60cee9d5f07acecabe03948ca87ffc664726b724b6666db21836c8d5
5
5
  SHA512:
6
- metadata.gz: ef40dcf9cecf8f212386b9d8302dd38f713fc531b7ec087e51b67fd994b5f29e276e79e01c7968a8850b1bc31a019f23d2a8cb06eb3526869fc27f7e553d98b9
7
- data.tar.gz: b6bacaf914b37f59b3b7139bfdf61076013ef96db93ca95938e39f50e78f87c5cf432511a469c17dd8eeb216d71bc52031e34fea8e04887785e1dd4fa13cb843
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(topic: nil)
9
- @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
10
12
  end
11
13
 
12
14
  # @param [Event] domain_event
13
15
  def dispatch(domain_event)
14
- @topic.publish(
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 default_topic
23
- conn = Bunny.new(ENV['AMQP_CONNECTION']).start
24
- channel = conn.create_channel
25
- 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 && @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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusDomainEvents
3
- VERSION = '1.0.3'
3
+ VERSION = '1.1.0'
4
4
  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.3
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-01-30 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
@@ -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.7
77
+ rubygems_version: 3.2.10
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Ruby based domain eventing tools