是否可以在 Spring Cloud Stream 中配置多个绑定到同一个处理器?

Gab*_*man 3 spring-boot spring-cloud-stream spring-cloud-stream-binder-kafka

我有一个简单的 Spring 集成流程,它绑定到处理器以进行输入和输出。

我已经配置了 Kafka 绑定器来映射输入和输出主题。效果很好。

假设我想将 3 个 Kafka 主题绑定到输入,从而导致 3 个已配置的消费者从三个单独的 Kafka 主题中提取数据,然后由我的 SI 流进行处理。

是否可以将多个 Kafka 主题映射到我的处理器的输入?如果是这样,该配置会是什么样子?

Gar*_*ell 5

如果destination属性是逗号分隔的列表,将为每个目标创建侦听器容器并绑定到同一侦听器。

您还可以将该multiplex属性设置为 true,这样我们就只有一个容器侦听多个主题。

spring.cloud.stream.bindings.foo.consumer.multiplex=true

/**
 * When set to true, the underlying binder will natively multiplex destinations on the
 * same input binding. For example, in the case of a comma separated multiple
 * destinations, the core framework will skip binding them individually if this is set
 * to true, but delegate that responsibility to the binder.
 *
 * By default this property is set to `false` and the binder will individually bind
 * each destinations in case of a comma separated multi destination list. The
 * individual binder implementations that need to support multiple input bindings
 * natively (multiplex) can enable this property.
 */
private boolean multiplex;
Run Code Online (Sandbox Code Playgroud)

您必须设置 Multiplex 属性才能启用它。