Sha256: 9beea4976298af997febec308044975b86285baf7a37d0a00491ca3636c08f45

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

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

EM.run do

  # connect to the amqp server
  connection = AMQP.connect(:host => 'dev.rabbitmq.com', :logging => false)
  
  # open a channel on the AMQP connection
  channel = MQ.new(connection)

  # declare a queue on the channel
  queue = MQ::Queue.new(channel, 'queue name')

  # create a fanout exchange
  exchange = MQ::Exchange.new(channel, :fanout, 'all queues')

  # bind the queue to the exchange
  queue.bind(exchange)

  # publish a message to the exchange
  exchange.publish('hello world')

  # subscribe to messages in the queue
  queue.subscribe do |headers, msg|
    pp [:got, headers, msg]
    connection.close{ EM.stop_event_loop }
  end
  
end

__END__

[:got,
 #<AMQP::Protocol::Header:0x1186270
  @klass=AMQP::Protocol::Basic,
  @properties=
   {:priority=>0,
    :exchange=>"all queues",
    :consumer_tag=>"queue name",
    :delivery_tag=>1,
    :delivery_mode=>1,
    :redelivered=>false,
    :content_type=>"application/octet-stream",
    :routing_key=>""},
  @size=11,
  @weight=0>,
 "hello world"]

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
tmm1-amqp-0.5.5 examples/mq/simple.rb
tmm1-amqp-0.5.9 examples/mq/simple.rb
amqp-0.5.5 examples/mq/simple.rb
amqp-0.5.9 examples/mq/simple.rb