Module: Harmoniser::Publisher::ClassMethods

Defined in:
lib/harmoniser/publisher.rb

Instance Method Summary collapse

Instance Method Details

#harmoniser_publisher(exchange_name:) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/harmoniser/publisher.rb', line 10

def harmoniser_publisher(exchange_name:)
  @harmoniser_exchange_definition = Definition::Exchange.new(
    name: exchange_name,
    type: nil,
    opts: {passive: true}
  )
end

#publish(payload, opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/harmoniser/publisher.rb', line 18

def publish(payload, opts = {})
  raise_missing_exchange_definition unless @harmoniser_exchange_definition

  const_get(:HARMONISER_PUBLISHER_MUTEX).synchronize do
    harmoniser_exchange.publish(payload, opts)
  end
  Harmoniser.logger.debug { "Message published: exchange = `#{@harmoniser_exchange_definition.name}`, payload = `#{payload}`, opts = `#{opts}`" }

  harmoniser_exchange
end