0
votes

I have a ruby process to consume RabbitMQ queue :

AMQP.start(:host => $AMQP_URL) do |connection|
  @channel ||= AMQP::Channel.new(connection)
  @queue   ||= @channel.queue("results")

  @queue.subscribe do |body|
    puts "Received -> #{body}"       
    # Publish the same message again to the same queue 
  end
end

I know it is not practical, but I would love to know how am I supposed to publish the same message to the same queue, it didn't work out for me with direct channel, if there is anyways even just to keep the msg in the queue instead of deleting it or just to republish the msg again it would be great

Any ideas ?

1

1 Answers

1
votes

The proper way to do it would just be to reject the message with a negative acknowledgement, it will be automatically requeued:

@queue.subscribe do |metadata, payload|
  # reject and requeue
  channel.reject(metadata.delivery_tag, true)
end

Anyway, if you want to do the publish manually, the "metadata" parameter in the previous example will give you all the information you need.