Class: Mercury::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/mercury/sync.rb

Class Method Summary collapse

Class Method Details

.publish(source_name, msg, tag: '', amqp_opts: {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mercury/sync.rb', line 7

def publish(source_name, msg, tag: '', amqp_opts: {})
  conn = Bunny.new(amqp_opts)
  conn.start
  ch = conn.create_channel
  ch.confirm_select
  ex = ch.topic(source_name, Mercury.source_opts)
  ex.publish(WireSerializer.new.write(msg), **Mercury.publish_opts(tag, {}))
  ch.wait_for_confirms or raise 'failed to confirm publication'
ensure
  conn.close
end