Ad

Rabbitmq Queue Is Empty Although There Are Messages In The Queue

I'm sending messages from Java Spring Boot application to consumer which is Python application.

Everything works fine except when I enter command rabbitmqctl list_queues it shows that video_queue 0 which means there are no messages in the queue.

Consumer is receiving messages and doing some long process; so if I send multiple messages in a row there should be some messages that waiting on the queue. Am I right?

Producer:

@Component
public class VideoProducer {
    private Logger logger = LoggerFactory.getLogger(VideoProducer.class);
    private final static String BROKER_EXCHANGE_NAME = "video_exchange";
    private final static String ROUTING_KEY = "video_routing_key";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private VideoService videoService;

    @Autowired
    private Gson gson;

    public void produceVideo(VideoDTO video) {
            rabbitTemplate.convertAndSend(BROKER_EXCHANGE_NAME, ROUTING_KEY, gson.toJson(video));

        }
    }
}

Consumer

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channelConsumer = connection.channel()

# Video Consumer Settings
channelConsumer.exchange_declare(exchange='video_exchange',
                                 exchange_type='direct')
channelConsumer.queue_declare(queue="video_queue")
channelConsumer.queue_bind(queue="video_queue",
                           exchange="video_exchange",
                           routing_key="video_routing_key")


# Consumer Listener
def callback(ch, method, properties, body): 
   video_dto = eval(json.loads(body))  
   ##Something long process here
   print("Done..  ")    


channelConsumer.basic_consume(queue='video_queue',
                              auto_ack=True,
                              on_message_callback=callback)

print(' [*] Waiting for messages. To exit press CTRL+C')
channelConsumer.start_consuming()

Where can I see the messages on the queue that I declared? Because although I know there are messages on the queue I can't see them with the above command.

I am also using RabbitMQ management portal.
enter image description here

Ad

Answer

You can use RMQ management console to view the the messages and other information of RMQ. Consumers may consume more than one message and have them in the internal queue.To avoid this, set QOS to 1 and ack required to true. More on QOS : https://www.rabbitmq.com/consumer-prefetch.html

Ad
source: stackoverflow.com
Ad