Sha256: 7f10a37c83333f311535215a934f6ea2d17a3c1128e34a3ba3be534c34dd424a

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 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 "Channel-level exception handling" do |client|
  channel = AMQ::Client::Channel.new(client, 1)
  channel.open do
    puts "Channel #{channel.id} is now open"

    show_stopper = Proc.new {
      client.disconnect do
        puts
        puts "AMQP connection is now properly closed"
        EM.stop
      end
    }



    channel.on_error do
      puts "Oops, there is a channel-levle exceptions!"

      EM.add_timer(1.2) { show_stopper.call }
    end

    # amq.* names are reserevd so this causes a channel-level exception. MK.
    x = AMQ::Client::Exchange.new(client, channel, "amq.client.examples.extensions.x1", :direct)
    x.declare(false, false, false, true, false)


    EM.add_timer(1) do
      if channel.closed?
        puts "1 second later channel #{channel.id} is closed"
      end
    end

    Signal.trap "INT",  show_stopper
    Signal.trap "TERM", show_stopper

    EM.add_timer(2, show_stopper)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
amq-client-0.7.0.alpha16 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha15 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha14 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha13 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha12 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha11 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha10 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha9 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha8 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha7 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha6 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha5 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha4 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha3 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha2 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.7.0.alpha1 examples/eventmachine_adapter/channel_level_exception_handling.rb
amq-client-0.5.0 examples/eventmachine_adapter/channel_level_exception_handling.rb