Binder SPI
Binder SPI 由许多接口、开箱即用的实用程序类和发现策略组成,这些策略提供了用于连接到外部中间件的可插拔机制。
SPI 的关键点是Binder
接口,这是一种将输入和输出连接到外部中间件的策略。以下列表显示了Binder
接口:
public interface Binder<T, C extends ConsumerProperties, P extends ProducerProperties> {
Binding<T> bindConsumer(String bindingName, String group, T inboundBindTarget, C consumerProperties);
Binding<T> bindProducer(String bindingName, T outboundBindTarget, P producerProperties);
}
该接口是参数化的,提供了许多扩展点:
-
输入和输出绑定目标。
-
扩展的使用者和生产者属性,允许特定的 Binder 实现添加可以以类型安全的方式支持的补充属性。
典型的 Binder 实现包括以下内容:
-
实现
Binder
接口; -
Spring
@Configuration
创建类型为Binder
以及中间件连接基础设施。 -
一个
META-INF/spring.binders
在包含一个或多个 Binder 定义的类路径上找到的文件,如以下示例所示:kafka:\ org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration
前面已经提到,Binder 抽象也是框架的扩展点之一。因此,如果您在前面的列表中找不到合适的 binder,您可以在 Spring Cloud Stream 之上实现自己的 binder。
在如何从头开始创建 Spring Cloud Stream Binder 发布社区成员文档中
详细介绍,通过示例,实现自定义活页夹所需的一组步骤。
这些步骤也在Implementing Custom Binders 部分。 |