I am using spring-kafka to consume messages from a topic and we are using ConcurrentMessageListenerContainer.
Below is my application.yml
spring:
kafka:
listener:
concurrency: 2
consumer:
group-id: test-consumer-group
topic: CONSUMER-TOPIC
In the log we can see thread name is printed as test-consumer-group-0-C-1.
2021-10-04 11:04:41.254 [test-consumer-group-0-C-1]
I have checked the below file to see how this thread name is arrived.
Here, the thread name is like this: [group-id]-[concurrency]-C-X. Unable to understand how this X is arrived at.
It is well explained in the docs: https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/container-thread-naming.html
So, with a bean name of container, threads in this container will be named
container-0-C-1
,container-1-C-1
etc., after the container is started the first time;container-0-C-2
,container-1-C-2
etc., after a stop and subsequent start.
So, the X
in your equation belongs to the thread number when it is obtained from an executor to handle KafkaConsumer
interaction. See CustomizableThreadCreator
:
/**
* Return the thread name to use for a newly created {@link Thread}.
* <p>The default implementation returns the specified thread name prefix
* with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".
* @see #getThreadNamePrefix()
*/
protected String nextThreadName() {
return getThreadNamePrefix() + this.threadCount.incrementAndGet();
}