简体   繁体   中英

How to pause and resume RMQ consumer in Java

RMQConsumer in my code is a spring bean which is initialised at the time of Spring container initialisation. It starts listening to RMQ messages on the queue as soon that Spring bean is ready irrespective of the whole Spring container is ready or not. I want to start the consumption of messages only when the kubernates pod status is 1/1. As during rolling deployment, old pods are not terminated unless new pods are 1/1 status, which causes almost double the amount of pod count and spikes the consumption rate which is not desired in my case of some reasons.

What i tried I removed the channel.basicConsume method of RMq api which was executed at Bean postConstruct. And added the code in a Rest controller method under endpoint '''/postStart''' which i configured in kubernates deployment file under lifecycle hook of postStart, which doesnt seems to work. The hook is called before spring application even prints its first log(verified with time stamps).

Can you check if readinessProbe will help in this use case.

Please refer below article which can help.

Promoting Liveness and Readiness as core Spring Boot concepts https://spring.io/blog/2020/03/25/liveness-and-readiness-probes-with-spring-boot

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