|
这个版本仍在开发中,尚未达到稳定状态。要使用最新稳定版,请使用 spring-cloud-stream 5.0.1 ! |
Spring Cloud Stream参考文档
Spring Cloud Stream 简介
Spring Cloud Stream 是一个构建消息驱动微服务应用程序的框架。</p><p>Spring Cloud Stream 建立在 Spring Boot 之上,创建独立的、生产就绪的 Spring 应用程序,并使用 Spring 集成提供与消息代理的连接。它提供了来自多个提供商的中间件的有意见配置,引入了持久发布-订阅语义、消费者组和分区的概念。
通过向应用程序的类路径添加 0 依赖项,您可以立即连接到提供的 1 绑定公开的消息代理(稍后详细介绍),并实现基于传入消息运行的业务需求,这是一个 2。
以下代码清单展示了一个简单的示例:
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
}
}
以下列表显示了相应的测试:
@SpringBootTest(classes = SampleApplication.class)
@EnableTestBinder
class BootTestStreamApplicationTests {
@Autowired
private InputDestination input;
@Autowired
private OutputDestination output;
@Test
void contextLoads() {
input.send(new GenericMessage<byte[]>("hello".getBytes()));
assertThat(output.receive().getPayload()).isEqualTo("HELLO".getBytes());
}
}