In integration development there are lot of patterns that we can follow based on project requirements. Circuit Breaker is one of them.
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:
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:
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
1. Select the Anypoint MQ Subscriber Source.
2. Click on the Advanced tab.
3. Provide the Circuit Breaker from Global Reference.
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:
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
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:
We will explain each and every part the above flow design below:
Circuit Breaker Configuration:
Go to global elements section create a Circuit breaker configuration as below:
This configuration can be shared across multiple Subscriber resources in the project.
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 Processing\Listening Strategy:
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.
MQ messages stores in queue after getting Nack
Please find sample Mule project in Github Error-Handling-using-Anypoint-MQ-Circuit-Breaker
No comments:
Post a Comment