首页 > 解决方案 > 尽管队列中有消息,但 Rabbitmq 队列为空

问题描述

我正在从 Java Spring Boot 应用程序向作为 Python 应用程序的消费者发送消息。

一切正常,除了当我输入命令时rabbitmqctl list_queues 它显示video_queue 0这意味着队列中没有消息。

消费者正在接收消息并做一些漫长的过程;所以如果我连续发送多条消息,应该有一些消息在队列中等待。我对吗?

制片人:

@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));

        }
    }
}

消费者

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()

我在哪里可以看到我声明的队列中的消息?因为虽然我知道队列中有消息,但我无法使用上述命令看到它们。

我也在使用 RabbitMQ 管理门户。
在此处输入图像描述

标签: javapythonrabbitmqspring-amqpspring-rabbit

解决方案


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


推荐阅读