0

I am processing records from my rabbitMQ. in order to avoid loss of messages from rabbitMQ i am using rabbitMQ acknowledgment strategey. For testing purpose i have raises the exception just before the code where i gave acknowledgment back to the rabbitMQ. as per the code that i have written rabbitMQ should not delete the message from queue untile the line in my code i.e "c.ack(delivery_info.delivery_tag)" is executed. Below is my code

begin
MessageService.with_channel do |c|  
  queue = c.queue(QUEUE_NAME, :durable => true)
  exchange = c.topic(TOPIC_NAME, :durable => true)
  queue.bind(exchange, :routing_key => "#{ROUTING_KEY_PREFIX}.#")
  available_messages = queue.message_count
  processed_messages = 0
  fact_object = {}
  while queue.message_count > 0 && processed_messages <= message_limit
    queue.pop(:manual_ack => true) do |delivery_info, properties, payload|
      rad_exam_hash_object = JSON.parse(payload)
      entity_manager,criteria = self.query_revenue_cost_calculation(rad_exam_hash_object)
      fact_object = self.revenue_cost_calculation_result(entity_manager,criteria)
      self.insert_data_into_table(fact_object)
      raise "exception"
      c.ack(delivery_info.delivery_tag)
    end
    processed_messages = processed_messages + 1
    available_messages = processed_messages - 1
  end
  [processed_messages, available_messages,fact_object]
end
rescue
  puts "got exception while processing messages"
end

Please help me in undestnding why rabbitMQ is deleting message from queue even if the line "c.ack(delivery_info.delivery_tag)" is not executed.

Sanjay Salunkhe
  • 2,665
  • 5
  • 28
  • 52

1 Answers1

0

Disclaimer: I don't know ruby. Messages are deleted from queue:

  • if queue is deleted
  • if they are acknowledged
  • if message TTL expires.

So if it's non of that, maybe it's in the way the pop works. This sounds to be calling AMQPs get and (based on the tutorials) subscribe seems to be calling AMQPs consume.

cantSleepNow
  • 9,691
  • 5
  • 31
  • 42