Spring Kafka Listner |阅读同样的信息
我有一个主题名“user”,其中userid将被删除,我想从这个主题中阅读并处理下面的功能Spring Kafka Listner |阅读同样的信息,spring,spring-boot,apache-kafka,spring-kafka,Spring,Spring Boot,Apache Kafka,Spring Kafka,我有一个主题名“user”,其中userid将被删除,我想从这个主题中阅读并处理下面的功能 1. process user leave data 2. process user salary data 我希望有两个侦听器指向相同的主题,读取相同的用户id并并行启动处理 @KafkaListener(topics = "${kafka.topic.user}",group="abc")) public void receive(String message) {
1. process user leave data
2. process user salary data
我希望有两个侦听器指向相同的主题,读取相同的用户id并并行启动处理
@KafkaListener(topics = "${kafka.topic.user}",group="abc"))
public void receive(String message) {
userService.processLeave(message);
}
@KafkaListener(topics = "${kafka.topic.user}",group="abc1"))
public void receive1(String message) {
userService.processPayRoll(message);
}
但我一直看到--processPayRoll总是被调用
我遗漏了什么?嗯,看起来你使用的是旧式的春季卡夫卡版本 不幸的是,
组
与消费者的组.id
无关。
这就是生命周期管理的containerGroup
您应该考虑基于不同的用户配置来配置不同的<代码> KafkaMessageListenerContainer < /代码>。在那里,您已经可以配置不同的
ConsumerConfig.GROUP\u ID\u CONFIG
最新版本具有@KafkaListener
结构,如:
/**
* If provided, the listener container for this listener will be added to a bean
* with this value as its name, of type {@code Collection<MessageListenerContainer>}.
* This allows, for example, iteration over the collection to start/stop a subset
* of containers.
* @return the bean name for the group.
*/
String containerGroup() default "";
/**
* Override the {@code group.id} property for the consumer factory with this value
* for this listener only.
* @return the group id.
* @since 1.3
*/
String groupId() default "";
/**
* When {@link #groupId() groupId} is not provided, use the {@link #id() id} (if
* provided) as the {@code group.id} property for the consumer. Set to false, to use
* the {@code group.id} from the consumer factory.
* @return false to disable.
* @since 1.3
*/
boolean idIsGroup() default true;
/**
*如果提供,则此侦听器的侦听器容器将添加到bean中
*使用此值作为其名称,类型为{@code Collection}。
*例如,这允许对集合进行迭代以启动/停止子集
*集装箱的数量。
*@返回组的bean名称。
*/
字符串containerGroup()默认为“”;
/**
*使用此值重写使用者工厂的{@code group.id}属性
*仅适用于此侦听器。
*@返回组id。
*@自1.3
*/
字符串groupId()默认为“”;
/**
*当未提供{@link#groupId()groupId}时,使用{@link#id()id}(如果
*提供)作为使用者的{@code group.id}属性。设置为false,以使用
*消费者工厂中的{@code group.id}。
*@return false禁用。
*@自1.3
*/
布尔idIsGroup()默认为true;
1.3.0.RC1候选版本现已在spring milestone repo中提供;预计将于本月底发布。