Rabbitmq 队列为空,尽管队列中有消息
Rabbitmq Queue is empty although there are messages in the queue
我正在从 Java Spring 引导应用程序发送消息给消费者,即 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 管理门户。
您可以从访问 localhost:15672 的 rabbitMQ 管理门户检查和管理队列,一旦任何接收方收到来自队列的消息,它将自动从队列中删除。因此,如果您想查看您的消息,最好通过管理门户进行检查,一旦任何接收者收到这些消息,这些消息就会被删除。
您可以使用RMQ管理控制台查看RMQ的消息等信息。
消费者可能会消费多个消息并将它们放在内部 queue.To 避免这种情况,将 QOS 设置为 1 并将 ack required 设置为 true。
有关 QOS 的更多信息:https://www.rabbitmq.com/consumer-prefetch.html
我正在从 Java Spring 引导应用程序发送消息给消费者,即 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 管理门户。
您可以从访问 localhost:15672 的 rabbitMQ 管理门户检查和管理队列,一旦任何接收方收到来自队列的消息,它将自动从队列中删除。因此,如果您想查看您的消息,最好通过管理门户进行检查,一旦任何接收者收到这些消息,这些消息就会被删除。
您可以使用RMQ管理控制台查看RMQ的消息等信息。 消费者可能会消费多个消息并将它们放在内部 queue.To 避免这种情况,将 QOS 设置为 1 并将 ack required 设置为 true。 有关 QOS 的更多信息:https://www.rabbitmq.com/consumer-prefetch.html