spring - 如何使用 Micrometer 获取 Spring Integration 队列中的消息数量?

标签 spring spring-integration spring-micrometer

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 this QueueChannel

但是:

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/

相关文章:

java - int-ftp :inbound-channel-adapter should be restart after a few minutes of work?

spring-boot - GraphQL + Spring 启动 : how to collect (error) metrics?

java - 测试 ehcache

java - 从 JBoss 中的 servlet 访问 Spring bean

java - com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer 类没有默认(无参数)构造函数

java - 处理多线程拆分器/聚合器编排内部的异常以转到聚合器而不是 MessagingGatewaySupport 的 errorChannel

java - 如何在 spring-integration 中模拟 InboundAdapter?

java - 千分尺与 DynaTrace 的集成

java - Spring Boot 千分尺计数取消

spring - JAXBElement : providing codec (/converter? ) 对于类 java.lang.Class