Spring 的Metrics and Management: MessageChannel
Metric Features描述:
If it is a
QueueChannel
, you also see statistics for the receive operation as well as the count of messages that are currently buffered by thisQueueChannel
但是:
These legacy metrics will be removed in a future release. See Micrometer Integration.
其中描述:
The Counter Meters for receive operations on pollable message channels have the following names or tags:
name
:spring.integration.receive
[...]
这听起来像是只计算已收到的消息数量。队列中的消息数量似乎无法获得,即使通过计算接收-发送
也无法获得(因为没有发送
)。
那么,使用 Spring Integration 和 Micrometer,是否可以读取队列大小?怎么办?
最佳答案
我认为我们需要为此队列大小值注册一个Gauge
:
/**
* A gauge tracks a value that may go up or down. The value that is published for gauges is
* an instantaneous sample of the gauge at publishing time.
*
* @author Jon Schneider
*/
public interface Gauge extends Meter {
这是一个相应的构建器:
/**
* A convenience method for building a gauge from a supplying function, holding a strong
* reference to this function.
*
* @param name The gauge's name.
* @param f A function that yields a double value for the gauge.
* @return A new gauge builder.
* @since 1.1.0
*/
@Incubating(since = "1.1.0")
static Builder<Supplier<Number>> builder(String name, Supplier<Number> f) {
欢迎提出 GH 问题来改进!
目前,可能可以通过具有 QueueChannel.getQueueSize()
委托(delegate)的外部 Gauge
实例来实现。
关于spring - 如何使用 Micrometer 获取 Spring Integration 队列中的消息数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63129028/