Difference between group id, Client id and id in KafkaListener Spring Boot

12,326

Your groupId understanding is correct.

The id is like a bean name in Spring Framework. However this one is used in the KafkaListenerEndpointRegistry boundaries only. So, if you need a lifecycle control over the particular KafkaListenerContainer created for the mentioned @KafkaListener, you need to inject KafkaListenerEndpointRegistry and use the mentioned getListenerContainer() for the appropriate id.

The clientIdPrefix is reflection of exact client.id property of the Kafka Consumer:

An id string to pass to the server when making requests. The purpose of this is to be able to track the source of requests beyond just ip/port by allowing a logical application name to be included in server-side request logging.

Share:
12,326
Am1rr3zA
Author by

Am1rr3zA

I am interested in: 1- Big Data 2- Programming 3- Dota All Stars 4- new technology

Updated on June 04, 2022

Comments

  • Am1rr3zA
    Am1rr3zA almost 2 years

    I am starting to work with Spring Boot 2 and Spring Kafka, I don't quite understand what's the difference between group id, Client id, and id in in KafkaListener interface.
    I know group ID is used by Kafka broker to manage multiple Consumer in the same group, but what about the others? what advantage do I get by setting them? where can I see the effect of setting or not setting them?

    Based on their java doc :

    /**
         * The unique identifier of the container managing for this endpoint.
         * <p>If none is specified an auto-generated one is provided.
         * @return the {@code id} for the container managing for this endpoint.
         * @see org.springframework.kafka.config.KafkaListenerEndpointRegistry#getListenerContainer(String)
         */
    String id() 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 provided, overrides the client id property in the consumer factory
     * configuration. A suffix ('-n') is added for each container instance to ensure
     * uniqueness when concurrency is used.
     * @return the client id prefix.
     * @since 2.1.1
     */
    String clientIdPrefix() default "";
    
  • Am1rr3zA
    Am1rr3zA about 6 years
    what are they gonna do in case of scaling my Kafka consumer horizontally? do they provide any help in case of tracking or debugging if I set them (id and client id)? I still don't' understand the point of setting them
  • Artem Bilan
    Artem Bilan about 6 years
    The id is something internal for the Spring Application Context. This should not be unique globally. The groupId is indeed good option for scaling when you would like to have several competing consumers on the same topic. The clientIdPrefix is really useful to determine via monitoring system what and where is consuming. That's like a global identificator for your application.
  • Ena
    Ena over 2 years
    Please be carefull that if you specify the id property it will override the group id. Doc says: Note: When provided, this value will override the group id property in the consumer factory configuration, unless idIsGroup() is set to false or groupId() is provided.