Sha256: a6b9df0401394646efb6e3d2183bdca863d16015e67e79935cc259f196af8edd

Contents?: true

Size: 1.05 KB

Versions: 23

Compression:

Stored size: 1.05 KB

Contents

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

require "bundler"
Bundler.setup

$:.unshift(File.expand_path("../../../../lib", __FILE__))
require 'amqp'
require "amqp/extensions/rabbitmq"

puts "=> Demonstrating connection.blocked"
puts

# 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.

EventMachine.run do
  connection = AMQP.connect(:host => '127.0.0.1')

  connection.on_blocked do |conn, conn_blocked|
    puts "Connection blocked, reason: #{conn_blocked.reason}"
  end

  connection.on_unblocked do |conn, _|
    puts "Connection unblocked"
  end

  puts "Connecting to RabbitMQ. Running #{AMQP::VERSION} version of the gem..."

  AMQP::Channel.new(connection) do |ch|
    x  = ch.default_exchange

    puts "Publishing..."
    x.publish("z" * 1024 * 1024 * 24)
  end

  show_stopper = Proc.new {
    connection.close { EventMachine.stop }
  }

  EM.add_timer(120, show_stopper)
  Signal.trap('INT',  show_stopper)
  Signal.trap('TERM', show_stopper)
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
amqp-1.8.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.7.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.6.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.5.3 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.5.2 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.5.1 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.5.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.4.2 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.4.1 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.4.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.3.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.2.1 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.2.0 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.8 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.7 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.6 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.5 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.4 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.3 examples/extensions/rabbitmq/connection_blocking.rb
amqp-1.1.2 examples/extensions/rabbitmq/connection_blocking.rb