问题描述
如果队列中的消息数量大于某个阈值,我希望生产者不发送新消息.为此,我需要找出队列中当前有多少消息.有没有办法使用 MassTransit 框架来做到这一点?
I want the producer to not send new messages if the number of messages in the queue is greater than some threshold value.To do this, I need to find out how many messages are currently in the queue.Is there a way to do this using MassTransit framework?
推荐答案
MassTransit 仅使用传输的功能(您没有提到).队列大小和其他度量通常是各种管理 API 的一部分.例如,可以在没有管理 API(这是一个插件)的情况下部署 RMQ 集群或实例,因此您无论如何都无法获得这些度量.
MassTransit only uses the capabilities of a transport (which you haven't mentioned). Queue sizes and other measurements are usually parts of a management API of sorts. For example, an RMQ cluster or instance can be deployed without the management API (which is a plugin), so you can't get those measurements anyway.
对于 RMQ,您可以使用管理 API 或包装器,例如 EasyNetQ管理 API,用于获取您需要的指标.
For RMQ, you can use the management API or a wrapper, like EasyNetQ management API, to fetch the metrics you need.
这篇关于MassTransit RabbitMQ 获取队列大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!