Raj
Raj

Reputation: 1727

How can intercept ConcurrentMessageListenerContainer when I'm using ConcurrentKafkaListenerContainerFactory

I'm using spring-kafka-2.2.7.RELEASE and trying to create a consumer using @KafkaListener at method level in conjunction with ConcurrentKafkaListenerContainerFactory. As per my understanding, this would create a ConcurrentMessageListenerContainer.

  1. Is there an interceptor to intercept this container creation so that I can inject my custom logic to build groupId?

  2. If I have two different methods using @KafkaListener to consumer two different topics, would it create two ConcurrentMessageListenerContainers?

Upvotes: 0

Views: 362

Answers (1)

Gary Russell
Gary Russell

Reputation: 174729

  1. If you have @KafkaListener(id = "foo", ..., autoStartup = "false") you can auto wire the KafkaListenerEndpointRegistry, and then...

    registry.getListenerContainer("foo").getContainerProperties().setGroupId(...); registry.getListenerContainer("foo").start();

However, you can simply use

@KafkaListener(... groupId "${some.property}")

or

@KafkaListener(... groupId "#{someSpelExpression}")

if all you want to do is set the group id.

  1. Yes, a separate container is created for each annotated method.

Upvotes: 2

Related Questions