此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 spring-cloud-stream 4.1.4spring-doc.cadn.net.cn

Binder 抽象

Spring Cloud Stream 为 KafkaRabbit MQ 提供了 Binder 实现。 该框架还包括一个测试 Binder,用于将应用程序作为 spring-cloud-stream 应用程序进行集成测试。有关更多详细信息,请参阅 [测试] 部分。spring-doc.cadn.net.cn

Binder 抽象也是框架的扩展点之一,这意味着您可以在 Spring Cloud Stream 之上实现自己的 Binder。 在如何从头开始创建 Spring Cloud Stream Binder 中,发布社区成员文档 具体来说,通过一个示例,实现自定义 Binder 所需的一组步骤。 这些步骤也会在Implementing Custom Binders部分。spring-doc.cadn.net.cn

Spring Cloud Stream 使用 Spring Boot 进行配置,而 Binder 抽象使 Spring Cloud Stream 应用程序能够灵活地连接到中间件。 例如,部署人员可以在运行时动态选择外部目标(例如 Kafka 主题或 RabbitMQ 交换)和输入之间的映射 以及消息处理程序的输出(例如函数的 input 参数及其 return 参数)。 这种配置可以通过外部配置属性提供,也可以以 Spring Boot 支持的任何形式(包括应用程序参数、环境变量和application.ymlapplication.properties文件)。 在 Spring Cloud Stream 简介 部分的 sink 示例中,将spring.cloud.stream.bindings.input.destinationapplication 属性设置为raw-sensor-data使其从raw-sensor-dataKafka 主题或从绑定到raw-sensor-dataRabbitMQ 交易所。spring-doc.cadn.net.cn

Spring Cloud Stream 会自动检测并使用在 Classpath 上找到的 Binder。 您可以将不同类型的中间件与相同的代码一起使用。 为此,请在构建时包含不同的 Binder。 对于更复杂的用例,您还可以将多个 Binder 与应用程序打包在一起,并让它在运行时选择 Binder(甚至是否为不同的绑定使用不同的 Binder)。spring-doc.cadn.net.cn