java - 尽管队列中有消息,但 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()
我在哪里可以看到我声明的队列中的消息?因为虽然我知道队列中有消息,但我无法使用上述命令看到它们。
解决方案
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
推荐阅读
- netlogo - 仅使用补丁在 Netlogo 中显示字母?
- html - 如何让我的 SVG 使用 css 或 javascript 在鼠标悬停时进行动画处理?
- python - sklearn 的分类报告是否要求输入 x 和 y 的长度相同?
- terminal - 腻子是否支持 SET_ANY_EVENT_MOUSE ,如果是,如何启用它?
- console - Where does ActiveMQ Artemis Console store address and queue definitions?
- linux - 错误:尝试进行简单的系统调用时类型冲突
- javascript - req.body 是使用 express 的简单 HTML 表单中的空对象
- machine-learning - 准确率是准确率和召回率的函数
- java - 在Java中将元素放入HashMap
- applescript - 在 Mojave Filemaker 中通过 applescript 访问会引发权限错误