Sha256: 3687e999dc332c6c98106b8b5283e74cbb98ead6acd25f6ca16431f25e2f1b7a

Contents?: true

Size: 813 Bytes

Versions: 98

Compression:

Stored size: 813 Bytes

Contents

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

require "bundler"
Bundler.setup

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

require 'bunny'

conn = Bunny.new(:heartbeat_interval => 8)
conn.start

ch = conn.create_channel
x  = ch.topic("bunny.examples.recovery.topic", :durable => false)
q  = ch.queue("bunny.examples.recovery.client_named_queue2", :durable => true)
q.purge

q.bind(x, :routing_key => "abc").bind(x, :routing_key => "def")

loop do
  sleep 8
  body = rand.to_s

  begin
    x.publish(body, :routing_key => ["abc", "def"].sample)
    puts "Published #{body}"
  # happens when a message is published before the connection
  # is recovered
  rescue Exception => e
  end

  sleep 1.5
  _, _, payload = q.pop
  if payload
    puts "Consumed #{payload}"
  else
    puts "Consumed nothing"
  end
end

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
bunny-2.11.0.pre1 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.10.0 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.9.2 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.9.1 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.7 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.7.4 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.8.1 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.9.0 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.7.3 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.8.0 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.7.2 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.7.1 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.7.0 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.6 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.5 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.4 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.3 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.2 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.1 examples/connection/automatic_recovery_with_basic_get.rb
bunny-2.6.0 examples/connection/automatic_recovery_with_basic_get.rb