Sha256: 774c44332fe6dc3c146cbfd49f9de28d18a9f5b4d9ebcbf23a7ca4ba2a4ce75c

Contents?: true

Size: 679 Bytes

Versions: 2

Compression:

Stored size: 679 Bytes

Contents

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

require "rubygems"
require "amqp"

AMQP.start("amqp://guest:guest@dev.rabbitmq.com:5672") 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 new message"
      end

      EventMachine.add_timer(0.3) do
        queue.unsubscribe
        puts "Unsubscribed. Shutting down..."

        connection.close {
          EM.stop { exit }
        }
      end # EventMachine.add_timer
    end # channel.queue
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amqp-0.8.0.rc13 examples/guides/queues/08_unsubscribing_a_consumer.rb
amqp-0.8.0.rc12 examples/guides/queues/09_unsubscribing_a_consumer.rb