Search code examples
spring-kafka

Spring Kafka thread naming convention


I am trying to understand the Spring Kafka Containter Factory thread naming convention while creating the threads based on concurrency.

I am using spring-kafka:1.2.1.RELEASE release and I am finding below details from the documentation. https://docs.spring.io/autorepo/docs/spring-kafka-dist/1.2.1.BUILD-SNAPSHOT/reference/htmlsingle/#_container_thread_naming

If you don’t provide executors, SimpleAsyncTaskExecutor s are used; these executors create threads with names -C-n (consumer thread) and -L-n (listener thread). For the ConcurrentMessageListenerContainer, the part of the thread name becomes -m, where m represents the consumer instance. n increments each time the container is started. So, with a bean name of container, threads in this container will be named container-0-C-1 and container-0-L-1, container-1-C-1 etc., after the container is started the first time.

In my app I am seeing threads are getting created eventListener-0-C-1 , eventListener-2-C-1 , eventListener-1-C-1 during the server startup however, while consuming the message on the Listener method I am seeing thread names are eventListener-0-L-1 , eventListener-1-L-1 and eventListener-2-L-1, which is different. There is no separate executor on my app and its using the ConcurrentKafkaListenerContainerFactory as part of initial configuration.

Appreciate if someone can provide some internals around this. Thanks.


Solution

  • 1 2.x is no longer supported. Upgrade to at least 1.3.9. It has a much simpler threading model, thanks to KIP-62. The latest release is 2.2.3 and has many improved features over 1.x.

    With the old threading model there were two threads per consumer. One to poll and one to invoke the listener.