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")
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.
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.
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.
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 ...
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With