|
此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 spring-cloud-stream 4.3.0! |
显式绑定创建
在上一节中,我们解释了如何由Function,Supplier或Consumer应用程序提供的 bean。
但是,有时可能需要显式创建绑定,其中绑定未绑定到任何函数。这通常是为了
支持与其他框架的集成StreamBridge.
Spring Cloud Stream 允许您通过以下方式显式定义输入和输出绑定spring.cloud.stream.input-bindings和spring.cloud.stream.output-bindings性能。注意到属性名称中的复数允许您通过简单地用作分隔符来定义多个绑定。
只需以以下测试用例为例:;
@Test
public void testExplicitBindings() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
TestChannelBinderConfiguration.getCompleteConfiguration(EmptyConfiguration.class))
.web(WebApplicationType.NONE)
.run("--spring.jmx.enabled=false",
"--spring.cloud.stream.input-bindings=fooin;barin",
"--spring.cloud.stream.output-bindings=fooout;barout")) {
. . .
}
}
@EnableAutoConfiguration
@Configuration
public static class EmptyConfiguration {
}
如您所见,我们声明了两个输入绑定和两个输出绑定,而我们的配置没有定义任何函数,但我们能够成功创建这些绑定并访问它们相应的通道。