Spring Cloud Stream 参考文档
Spring Cloud Stream 简介
Spring Cloud Stream 是一个用于构建消息驱动微服务应用程序的框架。 Spring Cloud Stream 基于 Spring Boot 构建,用于创建独立的、生产级的 Spring 应用程序,并使用 Spring Integration 提供与消息代理的连接。 它提供了对多家供应商中间件的规范配置,引入了持久化发布-订阅语义、消费者组和分区等概念。
通过将 spring-cloud-stream
依赖项添加到应用程序的类路径中,您可以立即连接到由提供的 spring-cloud-stream
绑定器(稍后将详细介绍)公开的消息代理,并且可以实现您的功能需求,该需求由 java.util.function.Function
根据传入消息运行。
以下清单显示了一个快速示例:
@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());
}
}