File: disabled_automatic_recovery.rb

package info (click to toggle)
ruby-bunny 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 10,256; sh: 70; makefile: 8
file content (34 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env ruby
# encoding: utf-8

require "bundler"
Bundler.setup

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

require 'bunny'

conn = Bunny.new(heartbeat_timeout: 8, automatically_recover: false)
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 1.5
  body = rand.to_s
  puts "Published #{body}"
  x.publish(body, :routing_key => ["abc", "def"].sample)

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