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:

  • 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:

flow-design-circuit-breaker

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:


circuit-breaker-configuration
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.
                                                       

subscriber-circuit-breaker-config

 
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:

amq-subscriber-configuration

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:

  1. Configure the Subscribe processor
  2. Subscriber Type – Prefetch
  3. Max Local Messages –  default it to 5, you can change based on requirement for further tuning.
  4. 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,


error-propagate-type


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.

nack-token-vars




You can use Ack the message so that the message is removed from the queue in case of success scenarios.

ack-token-vars


This ackToken you can store in variable which can be used for Ack/Nack of the message.

set-attributes
MQ messages stores in queue after getting Nack

mq-msg-properties-details


Please find sample Mule project in Github Error-Handling-using-Anypoint-MQ-Circuit-Breaker

By Manish Kumar

I am having around 10 years of IT experience in Integration Architecture, Requirement gathering, Effort Estimation, Application Design\Development\Testing and Deployment including 5+ years of experience in MuleSoft ESB and Hybrid Integrations. DevOps and Cloud Integration is my area of interest.

28 thoughts on “Anypoint MQ Circuit Breaker – Mule4”
  1. 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.

  2. 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…

  3. Thank you for sharing your thoughts. I really appreciate your efforts and I am
    waiting for your further write ups thank you once again.

Leave a Reply

Your email address will not be published. Required fields are marked *