Skip to content

Instantly share code, notes, and snippets.

@we4tech
Last active August 1, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/2f273d37005f2e5af512e7692acf56d3 to your computer and use it in GitHub Desktop.
Save we4tech/2f273d37005f2e5af512e7692acf56d3 to your computer and use it in GitHub Desktop.
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