Search code examples
ruby-on-railsrabbitmqbunny

RabbitMQ Timeout::Error: IO timeout when reading 7 bytes


I use Ubuntu14.04, Rail 5, RabbitMQ (server 3.6.5), Bunny 2.5.1

I implemented Rabbit to servise, and tried to test it.

I wrote next ruby script:

def rabbit_test
  s_time = Time.current
  10_000.times do |n|
    Mq::RabbitService.new('test_queue').publish(n.to_s)
  end
  p "###############################"
  p "RabbirMQ Diff: #{Time.current - s_time}"
  p "###############################"
end

where Mq::RabbitService service include initialize Bunny, connection, creating queue etc

it other terminal I run

Mq::RabbitService.new('test_queue').subscribe

for start it works good, but I can push ONLY 827 messages (I don't know why exactly 837, but it is constantly same number).

After that my publisher raise error:

[8] pry(main)> rabbit_test
E, [2016-08-19T15:17:02.445820 #6409] ERROR -- #<Bunny::Session:0x6fb39858 [email protected]:5672, vhost=/, addresses=[192.168.1.67:5672]>: Got an exception when receiving data: IO timeout when reading 7 bytes (Timeout::Error)
Timeout::Error: IO timeout when reading 7 bytes
from /home/oleg/.rvm/gems/ruby-2.3.1/gems/bunny-2.5.1/lib/bunny/cruby/socket.rb:52:in `rescue in read_fully'

Also I've tried: add new user with admin privileges, tried add IP instead localhost address (like 192.168.0.11) result the same.

EDITED

I use my service for RabbitMQ connection Mq::RabbitService gist

BUT

def rabbit_test
  s_time = Time.current
  1_000.times do |n|
    connection = Bunny.new(host: '192.168.1.67', port: 5672, user: 'oleg', password: '111111').start
    channel = connection.create_channel
    channel.queue('queue_name', auto_delete: true)
    exchange = channel.default_exchange
    exchange.publish(n.to_s, routing_key: 'queue_name')
    channel.close
  end
  p "###############################"
  p "RabbirMQ Diff: #{Time.current - s_time}"
  p "###############################"
end

doesn't work too

Maybe someone know what I do wrong?

Thanks


Solution

  • You create a new connection for each loop and keep it open. You only close the channel; these are two different things. With older releases of Bunny I experienced issues with this approach. You should try to reuse your connection or close it after all channels are closed. Maybe this can solve your issue too.