able of Contents
Circuit breakers handle error scenarios and message reprocessing strategy and monitor the API calls. Find the Circuit breakers State explanation below,
- Closed State – Everything is working as expected.
- Open State – Number of failures Like timeouts, reaches a threshold, circuit breakers will stop the processing further API requests.
MuleSoft has provided the Anypoint MQ component itself the circuit breaker capability.
Add the dependency on the pom file as below:
Below is the Circuit Breaker with Anypoint MQ Example:
Circuit Breaker Configuration:
On the global elements section, Create the Circuit breaker configuration as below:
This configuration can be used across multiple Subscriber resources in the project.
- On Error Types – Type of Errors which want to trigger Open State
- Errors Threshold – Number of Failures in Succession
- Trip Timeout – Duration of Circuit Open When the Error Threshold is reached
In Anypoint MQ Subscriber Configuration, Refer to Advanced and configure the Circuit Breaker on reference.
It will handle the error scenarios and message reprocessing strategy if there are any failures.
AMQ Message Processing Listening Strategy:
This explains, what we are going to follow to process messages from Anypoint MQ. This process helps in effectively handling reprocessing and retrying scenarios and simplifies the process from a maintenance perspective
Acknowledgement Mode needs to assign value as Manual. It will enable ACK to process the message post successful completion of the flow. So that, the message doesn’t get retried or consumed.
Once both are configured like above (Circuit Breaker and AMQ Listening Strategy) in our components, the messages will be reprocessed and retried in a configurable manner.
In case of Error Scenarios,
Based on the configuration on flows, once a failure is present, you can catch the error, and after Error Handling, Nack the message; so that, the message stays on the queue and will be subsequently redelivered.
You can use Ack the message; so that, the message is removed from the queue in case of success scenarios.
You can store this ack Token in a variable which can be used for Ack/Nack of the message.
At the application level, Circuit breakers are very useful to handle error scenarios and message reprocessing strategy and monitor the API calls on Anypoint MQ or other queues to notify or acknowledge when error raises.