因此根据 Spring 的文档,它将在 REST 端点和消息 channel 上发布指标。
当我得到预期结果时,REST 端点工作正常。不过,我想处理指标中的每个变化。因此它表示默认情况下会将消息发布到名为“metricsChannel”的 channel
我尝试创建以下类来监听此 channel ,但它似乎没有触发。 Spring Boot 应用程序的其他所有内容均保留默认值。
package services.core;
import org.springframework.stereotype.Service;
import org.springframework.integration.annotation.ServiceActivator;
@Service
public class MetricService {
@ServiceActivator(inputChannel = "metricsChannel")
public void handleMessage(org.springframework.messaging.Message<?> message) {
System.out.println("Message [" + message.toString() + "] is received");
}
}
最佳答案
我刚刚测试过并且效果很好:
@Bean
@ServiceActivator(inputChannel = "metricsChannel")
public MessageHandler metricsHandler() {
return System.out::println;
}
我已经在我们的网络套接字
中做到了这一点sample在服务器
部分。
添加了这个:
compile 'org.springframework.boot:spring-boot-starter-actuator'
到该项目 Gradle 配置。
当我启动客户端
应用程序时,我在控制台中看到了这一点:
GenericMessage [payload=Metric [name=gauge.response.time.star-star, value=26.0, timestamp=Tue Apr 14 16:03:53 EEST 2015], headers={metricName=gauge.response.time.star-star, id=08697a97-83c1-5000-f031-65f6797c0cd8, timestamp=1429016633672}]
GenericMessage [payload=Metric [name=counter.status.101.time.star-star, value=1, timestamp=Tue Apr 14 16:03:53 EEST 2015], headers={metricName=counter.status.101.time.star-star, id=8d070cb4-88e8-f5a7-6b83-6b27edf75bfc, timestamp=1429016633674}]
但是,是的:你的代码也很好。
关于java - 订阅 Spring Metrics channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29627061/