Adil Khan
Adil Khan

Reputation: 144

Spring Boot Kafka Multiple Consumers with different properties configuration using appication.yml/properties

I have seen examples where we have a java configuration class and we define multiple KafkaListenerContainer and pass the required containerType to @kafkaListener. But i am exploring if there are any ways to achieve the same using Spring Boot auto Kafka configuration via appication.yml/properties.

Upvotes: 2

Views: 1873

Answers (1)

Gary Russell
Gary Russell

Reputation: 174689

No; Boot will only auto-configure one set of infrastructure; if you need multiple, you need to define them as beans.

However, with recent versions (since 2.3.4), you can add a listener container customizer to the factory so you can customize each listener container, even though they are created by the same factory; some properties can also be overridden on the @KafkaListener annotation itself.

Example:

@Component
class Customizer {

    public Customizer(ConcurrentKafkaListenerContainerFactory<?, ?> factory) {
        factory.setContainerCustomizer(container -> {
            if (container.getContainerProperties().getGroupId().equals("slowGroup")) {
                container.getContainerProperties().setIdleBetweenPolls(60_000);
            }
        });
    }

}

Upvotes: 3

Related Questions