[rabbitmq-discuss] Consumer connection closes abruptly after one message

p2w tpletch001 at gmail.com
Wed Nov 16 15:25:58 GMT 2011


I have a rails 3.1 app (using thin server which is Event Machine
based) using the AMQP gem to connect to two server cluster on EC2. the
broker is running on ubuntu 11.10 and is version 2.6.1 with erlang
version 5.8.3.

I have an initializer that connects to and subscribes to a specifc
queue. when i place a single message into the queue then start the
server it consumes the message properly and the management console
shows a consumer attached to the queue, all good so far. then when i
place another message into the queue it gets consumed, but subsequent
to that message being consumed the broker log shows a "connection
closed abruptly" error and of course the consumer gets cut off.

I'm sure I'm doing something wrong in the initializer but can't figure
out what as its really pretty vanilla. Any help greatly appreciated...

here's the initializer code:

-------------------------------------------------------
connect_params = YAML::load_file(File.join(Rails.root, "config",
"rabbitmq.yml"))[Rails.env]

EventMachine.next_tick {
  AMQP.connect(connect_params['uri'], :auto_delete => false) do |
connection, open_ok|
    puts "Connected to MQ Server to Retreive API Submissions..."
    AMQP::Channel.new(connection) do |channel, open_ok|
      puts "Channel ##{channel.id} is open..."
      exchange = channel.direct('inbound', :durable => true)
      channel.on_error do |ch, close|
        puts "Handling channel-level error"
        connection.close
      end
      channel.queue('dropbox', :durable => true) do |queue,
declare_ok|
        queue.bind(exchange).subscribe do |metadata, payload|
          message_h = '#{metadata.headers}'
          message_p = '#{payload}'
          Resque.enqueue(ApiIntake, message_h, message_p)
        end
      end
   end
  end
  }


More information about the rabbitmq-discuss mailing list