Sha256: 8d32e37f2833aba9aef9930ec611197dad80f83553ac116956d93fcc7cdad541

Contents?: true

Size: 629 Bytes

Versions: 1

Compression:

Stored size: 629 Bytes

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require "rubygems"
require "amqp"

AMQP.start("amqp://guest:guest@dev.rabbitmq.com") do |connection, open_ok|
  AMQP::Channel.new do |channel, open_ok|
    exchange = channel.fanout("amq.fanout")

    channel.queue("", :auto_delete => true, :exclusive => true) do |queue, declare_ok|
      queue.bind(exchange).subscribe do |headers, payload|
        puts "Received a message: #{payload.inspect}. Shutting down..."

        connection.close {
          EM.stop { exit }
        }
      end

      EventMachine.add_timer(0.2) do
        exchange.publish("Ohai!")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amqp-0.8.0.rc13 examples/guides/queues/06_subscribe_to_receive_messages.rb