Reputation: 405
Is there a way to implement a circuit breaker pattern with Spring Kafka based consumer . I am wondering while implementing my Spring kafka consumer is it possible to stop consuming records if there is a failure to process the data based on some external system and which throws a network error. However if the network issue is resolved the consumer should again process normally.
Upvotes: 6
Views: 13677
Reputation: 99
You can refer this solution if you want to stop consuming messages when downstream service or DB is down.
Example
In this case you can setup circuit breaker on Service A. Whenever External Service B is down then this circuit will open. Then upon state transition of this circuit breaker, call your listener/bindings(if you are using spring-cloud-stream) to stop/pause consumer. So your messages will stay on queue/topic until the circuit breaker is closed again & you dont have to deadletter messages or put them onto error queue/topic.
You can refer below link for detailed solution which uses Resilience4j for circuit breaker implementation & spring-cloud-stream for consumer.
https://dublincoders.com/circuit-breaker-kafka/
Upvotes: 9
Reputation: 1054
Given:
Then:
This is how I have done it :-) If you have found a better way please share!
Upvotes: 1
Reputation: 665
Retries with Dead Letter Queue (DLQ) is a good pattern to handle consumer failure, and Circuit Breaker pattern is good to handle producer issues.
Upvotes: 3