File: connection_blocked.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 (35 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (7)
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
35
#!/usr/bin/env ruby
# encoding: utf-8

require "rubygems"
require "bunny"

puts "=> Demonstrating connection.blocked"
puts

conn = Bunny.new
conn.start

ch   = conn.create_channel
x    = ch.fanout("amq.fanout")

# This example requires high memory watermark to be set
# really low to demonstrate blocking.
#
# rabbitmqctl set_vm_memory_high_watermark 0.00000001
#
# should do it.

conn.on_blocked do |connection_blocked|
  puts "Connection is blocked. Reason: #{connection_blocked.reason}"
end

conn.on_unblocked do |connection_unblocked|
  puts "Connection is unblocked."
end

x.publish("z" * 1024 * 1024 * 16)

sleep 120.0
puts "Disconnecting..."
conn.close