Sha256: 3d3aa9f574bb680b8fb93eca936492ead3c499c66bcf372659912dbc7126868c

Contents?: true

Size: 1.5 KB

Versions: 15

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8

# simple_consumer_08.rb

# N.B. To be used in conjunction with simple_publisher.rb

# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
# and that it is running on 'localhost'.

# If this is not the case, please change the 'Bunny.new' call below to include
# the relevant arguments e.g. b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')

# How this example works
#=======================
#
# Open up two console windows start this program in one of them by typing -
#
# ruby simple_consumer_08.rb
#
# Then switch to the other console window and type -
#
# ruby simple_publisher_08.rb
#
# A message will be printed out by the simple_consumer and it will wait for the next message
# until the timeout interval is reached.
#
# Run simple_publisher as many times as you like. When you want the program to stop just stop
# sending messages and the subscribe loop will timeout after 30 seconds, the program will
# unsubscribe from the queue and close the connection to the server.

$:.unshift File.dirname(__FILE__) + '/../lib'

require 'bunny'

b = Bunny.new(:logging => true)

# start a communication session with the amqp server
b.start

# create/get queue
q = b.queue('po_box')

# create/get exchange
exch = b.exchange('sorting_room')

# bind queue to exchange
q.bind(exch, :key => 'fred')

# subscribe to queue
q.subscribe(:consumer_tag => 'testtag1', :timeout => 30) do |msg|
  puts "#{q.subscription.message_count}: #{msg[:payload]}"
end

# Close client
b.stop

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
bunny-0.7.13 examples/simple_consumer_08.rb
bunny-0.7.12 examples/simple_consumer_08.rb
bunny-0.7.11 examples/simple_consumer_08.rb
bunny-0.7.10 examples/simple_consumer_08.rb
sparqcode_bunny-0.0.2 examples/simple_consumer_08.rb
bunny-0.7.9 examples/simple_consumer_08.rb
sparqcode_bunny-0.0.1 examples/simple_consumer_08.rb
bunny-0.7.8 examples/simple_consumer_08.rb
bunny-0.7.6 examples/simple_consumer_08.rb
bunny-0.7.5 examples/simple_consumer_08.rb
bunny-0.7.4 examples/simple_consumer_08.rb
bunny-0.7.3 examples/simple_consumer_08.rb
bunny-0.7.2 examples/simple_consumer_08.rb
bunny-0.7.1 examples/simple_consumer_08.rb
bunny-0.7 examples/simple_consumer_08.rb