In this article we will see how Circuit Breaker can be used and what we should consider while implementing it.
Circuit breaker design pattern is used when:
- To handle error scenarios and message reprocessing strategy.
Mulesoft has provided circuit breaker capability with Anypoint MQ component.
You can add dependency inside your pom as below:
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>3.1.0</version>
<classifier>mule-plugin</classifier>
</dependency>
Now, I will show you how you can design and configure your mule flows for implementing Circuit Breaker capability.
Below is the sample circuit breaker mule flow design:
Circuit Breaker Configuration:
On Error Types – Type of Errors based on which you want to Open the Circuit.
Errors Threshold – No. of Failures in Succession – Ex: 5
Trip Timeout – Duration to keep the Circuit Open once the ErrorThreshold is reached – Ex: 60 Minutes
Subscriber Configuration
Anypoint MQ Subscriber Source provides Circuit Breaking Capability.
1. Select the Anypoint MQ Subscriber Source.
2. Click on the Advanced tab.
3. Provide the Circuit Breaker from Global Reference.
AMQ Message ProcessingListening Strategy:
This section describes the methodology how we are going to follow to process messages from Anypoint MQ. This process helps in effectively handling reprocessing and retrying scenarios and also simplifies the process from a maintenance perspective.
Steps:
- Configure the Subscribe processor
- Subscriber Type – Prefetch
- Max Local Messages – default it to 5, you can change based on requirement for further tuning.
- Acknowledgment Mode – Set to MANUAL, As the Acknowledgement Mode is set to MANUAL, we need to Ack the message post successful completion of the flow. So that the message doesn’t get retried/consumed.
Circuit Breaker and AMQ Listening Strategy both need to be configured in our components where we want messages to be reprocessed and retried in a configurable manner.
In case of Error Scenarios,
Based on your requirement you can catch the error and subsequent to 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.
This ackToken you can store in variable which can be used for Ack/Nack of the message.
Please find sample Mule project in Github Error-Handling-using-Anypoint-MQ-Circuit-Breaker
Good post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis.
It’s always interesting to read content from other writers and practice a little something from other sites.
Thank you 🙂
I want to to thank you for this good read!! I definitely enjoyed every little bit of it.
I have got you bookmarked to look at new stuff you post…
Thank you for sharing your thoughts. I really appreciate your efforts and I am
waiting for your further write ups thank you once again.