简体   繁体   中英

Springboot - Spring Kafka - Lazy Container Factory initialization

With Spring JDBC Templates, you can initialize connections lazily with a simple flag. Is there a similar capability for Kafka Container Factories for Springboot 1.5.x / Spring Kafka 1.3.x deployments?

The best answer I have seen so far is to disable autoStart and manage the start on your own catching any exceptions that may occur during start up here - How to start spring application even if Kafka listener (spring-kafka) doesn't initialize

Is this the only way and is there any caveats when using KafkaListenerEndpointRegistry to self-manage the lifecycle of the container(s)?

Would Lazy annotation work with @KafkaListener, @Configuration class for Kafka configurations or similar component class? Shooting this question out there since there does not appear to be a documented approach for handling, while in parallel attempting some of these approaches in order to obtain feedback in parallel.

When using Springboot 1.5.x, how does this change (if any) with Springboot 2.1.x (or above) and compatible Spring Kafka version for those versions?

Lazy initialization of a listener container makes no sense. What would trigger the instantiation?

The KafkaTemplate lazily creates its producer on the first operation.

autoStartup and starting/stopping using the registry is the correct approach.

The version makes no difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM