Sha256: 1f09bcf01e863b9c9f4f5c55d6f5da008327712ef82d8f6f4979bf4b24beb107

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

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

__dir = File.dirname(File.expand_path(__FILE__))
require File.join(__dir, "..", "example_helper")

amq_client_example "Declare a new fanout exchange" do |connection|
  channel = AMQ::Client::Channel.new(connection, 1)
  channel.open do
    puts "Channel #{channel.id} is now open!"

    channel.on_error do |ch, close|
      puts "Handling a channel-level exception: #{close.reply_text}"
    end

    EventMachine.add_timer(0.4) do
      # these two definitions result in a race condition. For sake of this example,
      # however, it does not matter. Whatever definition succeeds first, 2nd one will
      # cause a channel-level exception (because attributes are not identical)
      AMQ::Client::Queue.new(connection, channel, "amqpgem.examples.channel_exception").declare(false, false, false, true) do |queue|
        puts "#{queue.name} is ready to go"
      end

      AMQ::Client::Queue.new(connection, channel, "amqpgem.examples.channel_exception").declare(false, true, false, false) do |queue|
        puts "#{queue.name} is ready to go"
      end
    end
  end


  show_stopper = Proc.new do
    $stdout.puts "Stopping..."

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

  Signal.trap "INT", show_stopper
  EM.add_timer(2, show_stopper)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
amq-client-0.7.0.alpha35 examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb
amq-client-0.7.0.alpha34 examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb
amq-client-0.7.0.alpha33 examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb
amq-client-0.7.0.alpha32 examples/eventmachine_adapter/error_handling/handling_a_channel_level_exception.rb