Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Kafka Consumer/Listener Group

Tags:

what is the difference in specifying group at the consumer

spring.kafka.consumer.group-id

vs specifying at the @KafkaListener?

@KafkaListener(topic="test", group = "test-grp")
like image 841
srini Avatar asked Oct 27 '17 16:10

srini


People also ask

How does Spring Kafka consumer work?

Consumer Configuration in Spring KafkaA ConsumerFactory and a KafkaListenerContainerFactory must be configured before messages can be consumed. POJO-based consumers can be configured with the @KafkaListener annotation once these beans are available in the Spring bean factory.

How use Kafka consumer in spring boot?

Add the “Spring for Apache Kafka” dependency to your Spring Boot project. Step 2: Create a Configuration file named KafkaConfig. Below is the code for the KafkaConfig. java file.

What is spring Kafka listener concurrency?

In general, concurrency is the ability to perform parallel processing with no affect on the end result. In Kafka, the parallel consumption of messages is achieved through consumer groups where individual consumers read from a given topic/partitions in parallel.

How does Spring Kafka listener work?

First of all, the KafkaListeners are a high level abstraction from Spring Kafka, Kafka doesn't round robin nothing at all (from the consumer perspective, it's different with the producers), if you have 3 consumers (same consumer-group + listening on the same topic), and 3 partitions in the topic, Kafka will rebalance ...


1 Answers

See the javadocs for the group property; it has nothing to do with the kafka group.id...

/**
 * 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.
 */

This has been renamed containerGroup in 1.3/2.0.

Those release versions also provide...

/**
 * 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;

Previously, you needed a container factory/consumer factory for each listener; these allow you to use one factory instance and override the group.id.

like image 84
Gary Russell Avatar answered Sep 21 '22 13:09

Gary Russell