Sha256: fcbb9cec64302821bcb60385d42d23b236e485d4045b80daea15954af9c86a5f

Contents?: true

Size: 1.07 KB

Versions: 21

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 => 'localhost', :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

21 entries across 21 versions & 6 rubygems

Version Path
adamh-amqp-0.6.3.1 examples/mq/internal.rb
brontes3d-amqp-0.6.4.0 examples/mq/internal.rb
brontes3d-amqp-0.6.4.1 examples/mq/internal.rb
brontes3d-amqp-0.6.4.2 examples/mq/internal.rb
brontes3d-amqp-0.6.4.3 examples/mq/internal.rb
brontes3d-amqp-0.6.4 examples/mq/internal.rb
fotonauts-amqp-0.6.1 examples/mq/internal.rb
fotonauts-amqp-0.6.4 examples/mq/internal.rb
tmm1-amqp-0.6.0 examples/mq/simple.rb
tmm1-amqp-0.6.1 examples/mq/internal.rb
tmm1-amqp-0.6.3 examples/mq/internal.rb
tmm1-amqp-0.6.4 examples/mq/internal.rb
amqp-0.7.0.pre examples/mq/internal.rb
totty-amqp-0.6.7.1 examples/mq/internal.rb
totty-amqp-0.6.7.1.totty examples/mq/internal.rb
brontes3d-amqp-0.6.7.1 examples/mq/internal.rb
amqp-0.6.7 examples/mq/internal.rb
amqp-0.6.6 examples/mq/internal.rb
amqp-0.6.5 examples/mq/internal.rb
amqp-0.6.4 examples/mq/internal.rb