ProstDev ProstDev
Tutorials Apr 13, 2021 · 4 min read

How to integrate Solace PubSub+ Cloud with MuleSoft - Negative Scenario (Error Handling)

Even though the error handling logic varies depending on use cases, business requirements, organizational processes, etc. I believe the core approach to error handling for message-based integrations would more or less remain the same for different applications. The most common approach consists of the following steps.

By Pravallika Nagaraja
Integrate Solace PubSub+ Cloud with MuleSoft· Part 2 of 2
  1. 1.How to integrate Solace PubSub+ Cloud with MuleSoft
  2. 2.How to integrate Solace PubSub+ Cloud with MuleSoft - Negative Scenario (Error Handling)
How to integrate Solace PubSub+ Cloud with MuleSoft - Negative Scenario (Error Handling)

GitHub repository with the Mule project can be found at the end of the post.

In my previous post (How to integrate Solace PubSub+ Cloud with MuleSoft), I explained the happy path of the Solace PubSub+ and MuleSoft Integration. In this post, let us see how we can handle an error efficiently.

Even though the error handling logic varies depending on use cases, business requirements, organizational processes, etc. I believe the core approach to error handling for message-based integrations would more or less remain the same for different applications.

The most common approach consists of the following steps:

  • In case of an error, the error is captured in the error handler logic.
  • Enrich the message with additional information that could be later used for reprocessing.
  • Keep track of the “deliveryCount” and other useful information in the “User Properties.”
  • Publish the message to an Error Topic for retrying.
  • Process the message from the error queue and depending on the “redelivery_count” attribute, either route it back to the source queue or the dead letter queue (or Dead Message Queue). Further reprocessing can happen by the operations team.

Let us see how I have implemented the above approach in the following use case. Before that, please take a look at my previous blog post on how to publish the message to the Solace Topic using the JMS “Publish” connector.

1) The message is received by the “On New Message” JMS Connector. The incoming message is transformed in the “Request Transformation” component, While attempting to create the Salesforce Account using the “Create” connector, there is an error (in case the account already exists). The choice router validates if a successful response is received from SFDC. In case of failure, an error is thrown.

(Note that you can also add an “Until Successful” block around the “Create” SFDC connector to retry for a specified amount of time before throwing an error.)

Subscribe flow receiving a JMS message, transforming it, and creating a Salesforce Account with a Choice router

The error is caught in the “On Error Propagate” error handler and invokes the “processSFDCError” flow.

Choice router branches plus an On Error Propagate handler referencing the processSFDCError flow

processSFDCError flow: Transform Message, Logger, and a sendNegativeAck Flow Reference

In case of Salesforce Connectivity error, then the error is thrown in the “Create” SFDC connector and caught in the “SFDC:ERROR” (On Error Propagate) as the error mapping is done in the connector level as shown in the following screenshot.

Salesforce Create connector Error Mapping mapping ANY error type to SFDC:ERROR

2) The message is published to the Error Topic as shown in the following screenshot:

sendNegativeAck flow setting error variables then publishing the message to the error queue

Note that I am capturing the “DELIVERYCOUNT”, “EXCEPTIONDETAILS” and “TIMESTAMP” in the “User Properties” field.

JMS Publish config to the error topic with DELIVERYCOUNT, EXCEPTIONDETAILS, and TIMESTAMP user properties

3) The message from the Error Queue is received in the retry-flow. In this flow, if the “redelivery_count” (attributes.properties.jmsxProperties.jmsxDeliveryCount) value is less than or equal to the “maxRedeliveryCount” variable, which will be fetched from the properties file, then the message will be published to the source Topic.

retry-flow listening on the error destination and setting flow, destinationTopic, and deadLetterTopic variables

Solace sample-test-error-queue showing one queued message after the first failure

Since the redelivery count is 1, the message is published back to the source Topic.

Mule Debugger on the retry-processing-flow Choice that checks redelivery_count against maxRedeliveryCount

Solace sample-test-queue showing the message republished to the source queue

4) The message is received by the subscribing flow and tries to process it. In case of error during the second time, the message is again published to the Error Topic with redelivery_count=2.

Mule Debugger variables showing redelivery_count = 2 after the second failure

5) In case of failure during the third retry, the message is again published to the Error Topic with redelivery_count=3.

Mule Debugger variables showing redelivery_count = 3 after the third failure

6) Since the “redelivery_count” now equals the “maxRedeliveryCount” variable, the message is published to the Dead Letter Topic or Dead Message Topic. A notification email can be triggered to the operations team for further processing of this message.

Debugger showing redelivery_count equals maxRedeliveryCount 3, so the message is published to the DLQ

Solace sample-test-dead-letter-queue showing the message after the max retries were exceeded

Solace Queues list with the dead-letter, error, and source test queues and their message counts

The message in the Error Topic is Acknowledged with the “retryAckId” variable as shown in the following screenshot.

retry-flow acknowledging the error-topic message with the retryAckId variable

7) In case of a Transformation error, the message can be sent directly to the Dead Letter Queue as retrying does not make any sense.

process-transformation-error flow publishing the message straight to the DLQ instead of retrying

Thank you for reading my blog post :)

Happy Learning,

Pravallika Nagaraja

GitHub repository

ProstDev GitHub - Solace MuleSoft Integration

FAQs

Frequently asked questions about this post.

  • What is the common approach to error handling for message-based integrations described here?

    The post lays out five steps: first the error is captured in the error handler logic, then the message is enriched with additional information for later reprocessing, then the deliveryCount and other useful details are tracked in the User Properties, then the message is published to an Error Topic for retrying, and finally the message is processed from the error queue and, depending on the redelivery_count, routed back to the source queue or to the dead letter queue (Dead Message Queue) for further reprocessing by the operations team.

  • Why might the Salesforce Create connector throw an error in this flow?

    When the incoming JMS message is transformed and the flow attempts to create the Salesforce Account using the Create connector, an error occurs if the account already exists, and the Choice router validates whether a successful response came back from SFDC, throwing an error on failure.

  • How do I retry for a while before throwing an error on the Salesforce Create connector?

    The post notes you can add an Until Successful block around the Create SFDC connector to retry for a specified amount of time before throwing an error.

  • Which user properties are captured when publishing the message to the Error Topic?

    When the sendNegativeAck flow publishes the message to the error topic, it captures DELIVERYCOUNT, EXCEPTIONDETAILS, and TIMESTAMP in the User Properties field.

  • When does the message get sent to the Dead Letter Queue instead of being retried?

    In the retry-flow the message is republished to the source Topic while the redelivery_count (attributes.properties.jmsxProperties.jmsxDeliveryCount) is less than or equal to the maxRedeliveryCount variable from the properties file; once redelivery_count equals maxRedeliveryCount, the message is published to the Dead Letter Topic and a notification email can be triggered to the operations team. A transformation error is sent straight to the Dead Letter Queue since retrying does not make sense.

More from this series

Integrate Solace PubSub+ Cloud with MuleSoft· Part 2 of 2
  1. 1.How to integrate Solace PubSub+ Cloud with MuleSoft
  2. 2.How to integrate Solace PubSub+ Cloud with MuleSoft - Negative Scenario (Error Handling)
Search

Loading search…