DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • GenAI: From Prompt to Production
  • SAP HANA Triggers: Enhancing Database Logic and Automation
  • GenAI: Running Prototypes Faster Than Wireframes
  • Business Logic Database Agent

Trending

  • Using Java Stream Gatherers To Improve Stateful Operations
  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • A Guide to Auto-Tagging and Lineage Tracking With OpenMetadata
  • Agile’s Quarter-Century Crisis

Efficient Error Handling With Anypoint MQ

In this article, take a look at efficient error handling with AnypointMQ and see the concept of DLQ and BLQ, learn about circuit breakers, and more.

By 
Priyam Shukla user avatar
Priyam Shukla
·
Oct. 27, 20 · Opinion
Likes (3)
Comment
Save
Tweet
Share
6.8K Views

Join the DZone community and get the full member experience.

Join For Free

What Are Queues?

Queue is a system where messages are pushed and are consumed by applications following a First In First Out (FIFO) rule.

Mulesoft Anypoint platform provides AnypointMQ service that is used by APIs. AnypointMQ can be configured in mule API during development. Messages can be sent and received from this queue asynchronously.

The Concept of DLQ and BLQ

Error handling is an essential part of any application and Queues can play an important role. Error handling can be done for 2 broad scenarios: Business logic errors (ex: HTTP:Bad Requests) and Server errors (ex: HTTP:Internal Server Error)

DLQ: Dead Letter Queue

When an error occurs due to server issues, we can send the original payload to a queue. This queue acts as DLQ. Pushing the payload to DLQ ensures zero loss of data. Whenever the server is up and running again, the queued messages can be reprocessed.

BLQ: Business Logic Error Queue

When an error occurs due to business logic compliance or any other code level issues (ex: null pointers), we can send the original payload to BLQ. Like DLQ, sending messages to BLQ ensures zero data loss. In case of data issues, these messages can be retrieved from BLQ and sent for reprocessing after rectifying the data gaps.

Why do we need DLQ and BLQ 

The reason for having separate queues for business and server errors is that it becomes very easy to differentiate between 1) payloads that could not get processed at all due to server issues and can be retried for processing directly (DLQ), and 2) payloads that have a possible data issue and need to be scanned before they can be reprocessed(BLQ).

The Concept of Nack and Ack

Ack stands for ‘Acknowledgement’. Nack on contrary to Ack stands for ‘No Acknowledgment’.

When an incoming payload from a queue is Acknowledged, it gets deleted from the queue. On similar lines, if it is Not Acknowledged, the message persists in the queue.

In case of server errors, you may want to retry processing for a certain number of times before sending the message to DLQ. However, in case of data issues, retrying makes no sense and these faulty messages can be sent to BLQ right away. This can be achieved through Nack and Ack.

Assume you decide to reattempt processing a message 5 times for a server unavailable error. For the first 4 times you will need to Nack the message during error handling which ensures that the message is available in the queue for reprocessing. The 5th time you can Ack it and send it to DLQ.

In case of bad requests or business logic errors you can Ack the message and send it to BLQ on first error occurance.

The Concept of Circuit Breaker

Circuit breaker is an inherent part of reprocessing strategy in error handling. Whenever the error occurrences cross a certain threshold, circuit breaker stops all processing for a certain cooling period.

Following is a high level model of error handling logic that implements BLQ and DLQ with separation of server and data issues.

The when condition for business logic errors can cover the following. Hence, the left out would be server errors that will automatically get redirected to second route.

Java
 




x


 
1
#[error.errors.errorType[0].identifier == "BAD_REQUEST" or error.errors.errorType[0].identifier == "EXPRESSION" or error.errorType.identifier== "SCHEMA_NOT_HONOURED" or error.errorType.identifier == "BAD_REQUEST" or error.errorType.identifier == "EXPRESSION" or error.errorType.identifier == "NOT_FOUND" or error.errors.errorType[0].identifier == "NOT_FOUND"]



You can maintain the max number of retries in a variable (vars.deliveryCount in example below) and test if the application has exhausted max retries.

Please note: if max number of retries is same as default in Anypoint MQ (i.e 10), you don’t need to explicitly Ack the message. It will automatically get acknowledged after 10 retries. However, if the number is lesser than 10, you need to add an Ack component in the second flow before Error_Description dataweave.


Business logic

Opinions expressed by DZone contributors are their own.

Related

  • GenAI: From Prompt to Production
  • SAP HANA Triggers: Enhancing Database Logic and Automation
  • GenAI: Running Prototypes Faster Than Wireframes
  • Business Logic Database Agent

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!