【发布时间】:2021-09-09 08:08:03
【问题描述】:
我正在将 Spring Cloud Stream 应用程序迁移到函数式方法。到目前为止,我使用的是提供 Spring Integration 的千分尺度量。见Spring Integration - Micrometer Integration。
自迁移以来,使用 StreamBridge 生成的消息不再生成指标。这似乎是因为 Spring Integration 在将通道定义为 bean 时创建了它的指标,而 StreamBridge 则动态创建了通道。
话虽如此,我的问题是:
- SCS 是否提供任何其他类型的指标?
- 如果没有,有什么方法可以强制应用程序事先将通道声明为 bean?
提前致谢。
更新
以下测试表明,即使在属性中定义绑定目标,也不会在启动时创建 bean。
用于测试的版本是:
弹簧启动:2.5.4
spring-cloud-stream: 3.1.3
class MessageChannelBeanTests {
@Test
void declaredOutputBindingsCreatesMessageChannelBeans() {
TestChannelBinderConfiguration.applicationContextRunner(MessageChannelBeanTestsConfiguration.class)
.withPropertyValues("spring.cloud.stream.bindings.myBinding.destination=myDestination",
"spring.cloud.stream.bindings.syso-in-0.destination=my-topic")
.run(context -> {
final Map<String, MessageChannel> channels = context.getBeansOfType(MessageChannel.class);
/*
* Just to see which channels are declared as a bean
* The ouput is:
*
* nullChannel
* errorChannel
* syso-in-0
* my-topic.anonymous.errors
*/
channels.entrySet()
.stream()
.map(Entry::getKey)
.forEach(System.out::println);
// Asserts that the channel is created as a bean even if the binding is set by properties
assertThat(channels)
.containsKey("myBinding");
});
}
@EnableAutoConfiguration
static class MessageChannelBeanTestsConfiguration {
@Bean
public Consumer<String> syso() {
return System.out::println;
}
}
}
请注意,创建的 MessageChannel bean 是:
nullChannel 错误频道 系统输入-0 我的主题.anonymous.errors
但是没有'myBinding'的踪迹
【问题讨论】:
标签: spring-cloud-stream micrometer