类路径上的多个绑定器

当类路径上存在多个绑定器时,应用程序必须指明每个目标绑定使用哪个绑定器。每个绑定器配置都包含一个 META-INF/spring.binders 文件,这是一个简单的属性文件,如下例所示

rabbit:\
org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration

其他提供的绑定器实现(如 Kafka)也存在类似的文件,自定义绑定器实现也应提供这些文件。键表示绑定器实现的标识名称,而值是配置类的逗号分隔列表,每个配置类都只包含一个类型为 org.springframework.cloud.stream.binder.Binder 的 Bean 定义。

绑定器选择可以全局执行,使用 spring.cloud.stream.defaultBinder 属性(例如,spring.cloud.stream.defaultBinder=rabbit),也可以单独执行,通过在每个绑定上配置绑定器。例如,一个处理器应用程序(分别用于读写,绑定名称为 inputoutput),它从 Kafka 读取并写入 RabbitMQ,可以指定以下配置

spring.cloud.stream.bindings.input.binder=kafka
spring.cloud.stream.bindings.output.binder=rabbit
© . This site is unofficial and not affiliated with VMware.