Spring Cloud Stream Reference Documentation
Preface
本部分将更详细地介绍如何使用 Spring Cloud Stream。它介绍了诸如创建和运行流应用程序之类的主题。
This section goes into more detail about how you can work with Spring Cloud Stream. It covers topics such as creating and running stream applications.
Introducing Spring Cloud Stream
Spring Cloud Stream 是用于构建消息驱动的微服务应用程序的框架。Spring Cloud Stream 基于 Spring Boot 来创建独立的、适合生产环境的 Spring 应用程序,并使用 Spring 集成提供与消息代理的连接。从多个供应商中提供了意见配置的中间件,引入了持久发布-订阅语义、消费者组和分区的概念。
Spring Cloud Stream is a framework for building message-driven microservice applications. Spring Cloud Stream builds upon Spring Boot to create standalone, production-grade Spring applications and uses Spring Integration to provide connectivity to message brokers. It provides opinionated configuration of middleware from several vendors, introducing the concepts of persistent publish-subscribe semantics, consumer groups, and partitions.
通过将 spring-cloud-stream
依赖项添加到应用程序的类路径,你可以立即连接到由提供的 spring-cloud-stream
绑定(稍后详细介绍)公开的消息代理,并且你可以实现你的函数需求,由 java.util.function.Function
运行(基于传入消息)。
By adding spring-cloud-stream
dependencies to the classpath of your application, you get immediate connectivity
to a message broker exposed by the provided spring-cloud-stream
binder (more on that later), and you can implement your functional
requirement, which is run (based on the incoming message) by a java.util.function.Function
.
以下清单显示了一个快速示例:
The following listing shows a quick example:
@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();
}
}
以下清单显示了对应的测试:
The following listing shows the corresponding test:
@SpringBootTest(classes = SampleApplication.class)
@Import({TestChannelBinderConfiguration.class})
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());
}
}