Sha256: 3a3eeb0720b670269d136c4ae758f73c2b879864428f526534d3ab7a4240d24c

Contents?: true

Size: 829 Bytes

Versions: 2

Compression:

Stored size: 829 Bytes

Contents

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

EM.run do
  
  # open a channel on the AMQP connection
  channel = MQ.new

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

  # use the default 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 from the queue 
  queue.subscribe do |headers, msg|
    pp [:got, headers, msg]
    AMQP.stop
  end
  
end

__END__

[:got,
 #<AMQP::Protocol::Header:0x118a438
  @klass=AMQP::Protocol::Basic,
  @properties=
   {:priority=>0,
    :delivery_mode=>1,
    :content_type=>"application/octet-stream"},
  @size=11,
  @weight=0>,
 "hello world"]

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
tmm1-amqp-0.5.3 examples/mq/simple.rb
amqp-0.5.3 examples/mq/simple.rb