对于最新稳定版本,请使用spring-cloud-stream 5.0.1spring-doc.cadn.net.cn

Spring Cloud Stream参考文档

前言

本部分将更详细地介绍您如何与 Spring Cloud Stream 进行交互。 它涵盖了创建和运行流应用等主题。spring-doc.cadn.net.cn

Spring Cloud Stream 简介

Spring Cloud Stream 是一个构建消息驱动微服务应用程序的框架。</p><p>Spring Cloud Stream 建立在 Spring Boot 之上,创建独立的、生产就绪的 Spring 应用程序,并使用 Spring 集成提供与消息代理的连接。它提供了来自多个提供商的中间件的有意见配置,引入了持久发布-订阅语义、消费者组和分区的概念。spring-doc.cadn.net.cn

通过向应用程序的类路径添加 0 依赖项,您可以立即连接到提供的 1 绑定公开的消息代理(稍后详细介绍),并实现基于传入消息运行的业务需求,这是一个 2。spring-doc.cadn.net.cn

以下代码清单展示了一个简单的示例:spring-doc.cadn.net.cn

@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();
	}
}

以下列表显示了相应的测试:spring-doc.cadn.net.cn

@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());
	}
}

Main Concepts

Spring Cloud Stream 提供了许多抽象和原语,可简化编写消息驱动型微服务应用程序。本参考手册其余部分提供了更多详细信息。spring-doc.cadn.net.cn