Class: NexusDomainEvents::Bus

Inherits:
Object
  • Object
show all
Defined in:
lib/nexus_domain_events/bus.rb

Overview

A domain events bus for dispatching events to

Instance Method Summary collapse

Constructor Details

#initialize(bunny: nil, topic_name: 'domain_events') ⇒ Bus

Returns a new instance of Bus.



8
9
10
11
12
# File 'lib/nexus_domain_events/bus.rb', line 8

def initialize(bunny: nil, topic_name: 'domain_events')
  @mutex = Mutex.new
  @bunny = bunny
  @topic_name = topic_name
end

Instance Method Details

#dispatch(domain_event) ⇒ Object

Parameters:



15
16
17
18
19
20
21
# File 'lib/nexus_domain_events/bus.rb', line 15

def dispatch(domain_event)
  ensure_connection!
  @exchange.publish(
    domain_event.to_json,
    routing_key: domain_event.message_name
  )
end