1

I have problem with StreamListener initializing. I can not solve my problem.

I am using Spring Cloud Stream Kafka and Spring Cache in my project. Spring Cache is initialized after SmartLifeCycle's start() method. But StreamListener starts consuming data before SmartLifeCycle's start() method. Because of this I can not complete my cache initialization before StreamListener starts to consume data and this causes problem for me.

Is there any way to delay StreamListener processing or to delay StreamListener bean initializing?

omerstack
  • 535
  • 9
  • 23
  • I could not find a solution for this. Should I change StreamListener to PolledConsumer? If this is the case, this time I can not consume records as batch (List) although I set yml config as batch-mode: true. I was able to do batch consuming in StreamListener. In polled Consumer is there any way to consume "batch" data as List? – omerstack Nov 20 '20 at 15:56
  • Is pausing and resuming the Consumer a solution for you? See here for an example: https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/3.0.8.RELEASE/reference/html/spring-cloud-stream-binder-kafka.html#pause-resume – sobychacko Nov 20 '20 at 17:15

1 Answers1

3

You can set the binding's autoStartup to false and start the binding later using the BindingsEndpoint bean.

See this answer.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 1
    The problem is solved with configuration autostartup = false and applying actuator's BindingsEndpoint start.Thank you very much. – omerstack Nov 23 '20 at 12:19