Sha256: 70ce3c14ac78ef99f4fbd6ce052932e74ba10db358a91024acdf2db01570303e

Contents?: true

Size: 1.51 KB

Versions: 23

Compression:

Stored size: 1.51 KB

Contents

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

require "bundler"
Bundler.setup

$:.unshift(File.expand_path("../../../lib", __FILE__))

require 'amqp'

puts "=> Example of automatic AMQP channel and queues recovery"
puts
AMQP.start(:host => "localhost") do |connection, open_ok|
  connection.on_error do |ch, connection_close|
    raise connection_close.reply_text
  end

  ch1 = AMQP::Channel.new(connection, 2, :auto_recovery => true)
  ch1.on_error do |ch, channel_close|
    raise channel_close.reply_text
  end

  connection.on_tcp_connection_loss do |conn, settings|
    puts "[network failure] Trying to reconnect..."
    conn.reconnect(false, 2)
  end

  queue = ch1.queue("", :auto_delete => true, :exclusive => true).bind("amq.fanout")
  queue.subscribe(:ack => true) do |metadata, payload|
    puts "[consumer1] => #{payload}"
    metadata.ack
  end
  consumer2 = AMQP::Consumer.new(ch1, queue)
  consumer2.consume.on_delivery do |metadata, payload|
    puts "[conusmer2] => #{payload}"
    metadata.ack
  end


  show_stopper = Proc.new {
    connection.disconnect { puts "Disconnected. Exiting…"; EventMachine.stop }
  }

  Signal.trap "TERM", show_stopper
  Signal.trap "INT",  show_stopper
  EM.add_timer(45, show_stopper)


  puts "This example needs another script/app to publish messages to amq.fanout. See examples/error_handling/hello_world_producer.rb for example"
  puts "Connected, authenticated. To really exercise this example, shut AMQP broker down for a few seconds. If you don't it will exit gracefully in 45 seconds."
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
amqp-0.9.10 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.9 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.8 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-1.0.0.pre2 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.7 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.6 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-1.0.0.pre1 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.5 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.4 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.3 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.2 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.1 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.0 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.0.pre3 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.0.pre2 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.9.0.pre1 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.8.4 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.8.3 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.8.2 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb
amqp-0.8.1 examples/error_handling/automatically_recovering_hello_world_consumer_that_uses_a_server_named_queue.rb