If the queue is empty for some time - the consumer does not read new messages

30 views
Skip to first unread message

Журин Влад

unread,
Nov 7, 2018, 3:23:26 PM11/7/18
to Ruby RabbitMQ libraries
Hello.

Help me please.

I have a Publisher and Consumer via Bunny.
I run this script and everything works fine.
But there are those days when there are no messages in the queue (usually 5-6 days). Then new messages are added to the queue, but the executable script does not read them. There is no error in the logs.
What could be wrong?

Launch task: 
#!/bin/bash

if ! [ -z $1 ]; then
env=$1;
else
env='development';
fi
echo == Start with RAILS_ENV = $env
bundle exec rake rabbit:subscribe RAILS_ENV=$env --trace 2>&1 >> log/consumer.log &
echo == The consumer is running!


My Task:
namespace :rabbit do
desc 'Subscribe msg'
task :subscribe => :environment do
begin
load 'app/services/external_receipt_service/atol.rb'
load 'app/services/external_receipt_service/base.rb'
Rabbitmq::Publisher.subscribe(ENV["RABBITMQ_RECEIPT_QUEUE"])

# How would you write a subscription loop when writing a long-running
# consumer, ie a ruby program with a a single thread that subscribe
# to a unique queue and processes the messages?

# prevent main thread from naturally terminating if q.subscribe(block: false)
loop{ sleep 2 }


rescue Interrupt => _
puts "Ctrl + C pressed"
rescue => e
puts e
end
end
end


My Consumer:
module RabbitMQ
class Consumer
def self.subscribe(queue)
exchange = channel.queue(queue, durable: true)
exchange.subscribe(ack: true) do |delivery_info, properties, payload|
begin
Rails.logger.debug(payload)
@channel.ack(delivery_info.delivery_tag)
rescue => e
@channel.nack(delivery_info.delivery_tag, false, true)
end
end
end

def self.channel
@channel ||= connection.create_channel
end

def self.connection
@conn = Bunny.new(ENV["RABBITMQ_SERVER"], {vhost: ENV["RABBITMQ_VHOST"], recover_from_connection_close: true})
@conn.start
end

def self.close
@conn.close
end
end
end

Michael Klishin

unread,
Nov 7, 2018, 3:26:26 PM11/7/18
to ruby...@googlegroups.com
We cannot possibly know.

See what the script and server log [1] around the time of event and metrics [2] that may be relevant.


--
Bunny: http://rubybunny.info
March Hare: http://rubymarchhare.info
 
IRC: #rabbitmq on irc.freenode.net
 
Post to the group: ruby...@googlegroups.com | unsubscribe: ruby-amqp+...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Ruby RabbitMQ libraries" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-amqp+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages