Skip to content

Instantly share code, notes, and snippets.

@we4tech we4tech/broadcaster.rb
Last active Aug 1, 2018

Embed
What would you like to do?
Rabbit Fanout Exchange Example
require 'bunny'
require 'irb'
STDOUT.sync = true
conn = Bunny.new("amqp://guest:guest@localhost:5672")
conn.start
ch = conn.create_channel
$x = ch.fanout('msgs')
IRB.start(__FILE__)
# $x.publish('1').publis('2')
require 'bunny'
STDOUT.sync = true
conn = Bunny.new("amqp://guest:guest@localhost:5672")
conn.start
ch = conn.create_channel
x = ch.fanout('msgs')
ch.queue('q1').bind(x).subscribe(block: true) do |info, meta, payload|
puts "payload: Q1 > #{payload}"
end
puts "Done"
require 'bunny'
STDOUT.sync = true
conn = Bunny.new("amqp://guest:guest@localhost:5672")
conn.start
ch = conn.create_channel
x = ch.fanout('msgs')
ch.queue('q2').bind(x).subscribe(block: true) do |info, meta, payload|
puts "payload: Q2 > #{payload}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.