1

My Spring boot application does two task

  1. Initialise cache
  2. kafka consumer

Already have a ApplicationEvent for cache initialisation and I want consumer to start listening the messages once cache initialisation is completed.

1 Answers1

1

If you are using @KafkaListener, give it an id and set autoStartup to false.

When you are ready, use the KafkaListenerEndpointRegistry bean to start the container.

registry.getMessageListenerContainer("myId").start().

If you are using a listener container bean, set its autoStartup to false and start() it when ready.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179