There is no tolerance for the loss of messages in some MuleSoft apps. A great example is a purchasing application for online orders. A company’s sales revenue would be impacted if even a single message was lost during a purchase transaction on the online platform. Get this interactive mulesoft training course from the well-experienced experts who would assist you in expertising concepts like mule4 basics, integration techniques in AnyPoint studio, performing the test, debug, deploy and manage the mulesoft applications, learn how to identify IT problems in the industry, etc.
However, while building a MuleSoft application, there are approaches to make certain that messages are delivered reliably. Using Mule transports that are transactional like JMS and VM is one option. Messages would be safely transmitted between an outward endpoint and an inbound endpoint, or among message processors inside a flowing mule by taking advantage of the built-in transactional functionality in JMS and VM transports.
Transactions are not supported by several means of transport, such as FTP, File, and HTTP. If a message processor throws an error while receiving messages via a listener of inbound HTTP, the application risks losing the messages. To achieve reliable message delivery for transports that are not transactional, a dependability pattern will be utilized.
A pattern of reliability is indeed a design strategy that combines inbound non-transactional transport (HTTP) and synchronous flow known as a reliable flow of acquisition, outbound transactional transport (VM) to ensure reliable message delivery. Receiving inbound messages, verifying them, and storing them in a queue via a JMS or VM connector is the responsibility of the reliable acquisition flow. The flow of logic in an application is where the business logic for the application is implemented.
It’s crucial to remember that the reliable flow of acquisition must use an asynchronous processing technique. This ensures the message was verified and sent in one thread to the outgoing VM destination. In addition, the logic of the application flow’s inbound VM endpoint should be set to transactional to enable rollbacks while processing messages when an exception occurs.
How To Solve: [pii_email_3a9d3c10845f8b9d77b2]
The Mule flow below shows how to integrate a reliable flow of acquisition with the logic flow of an application in Mule.
The steps in the process flow described above are as follows:
- In the reliable acquisition flow, a message is received synchronously by the listener of inbound HTTP.
- The payload has been configured, logged, also validated.
- When it is a valid message, it is queued and forwarded to the VM that is an outbound destination.
- The application logic flow’s VM that is an inbound endpoint retrieves from the queue’s message, initiates a newer transaction, and will set the payload.
- The message is subjected to business logic in an application, which either succeeds or fails.
- A rollback exception method will catch an exception and roll back the message to the original state.
- The logic flow of the application will retry to handle the message until the max no. of retries specified in the method of rollback exception has been reached.
- If the max no. of retries has been reached, the message would be forwarded to a Java Message Service queue for subsequent processing.
Source Code Example
The Mule flow source code is available below.
The following are few things to remember regarding the sample code:
- ActiveMQ connector is defined in sample code. ActiveMQ can be downloaded from the ActiveMQ website.
- For running sample code locally, go to this URL: “http://localhost:8081/test/reliable?input=fail”.
- Success or failure is the only valid query parameter input value. The rollback exceptions strategy is triggered when a failed input value is provided.
Overview of Reliability Patterns in Mule
A high-dependability application necessitates not only the reliability of the underlying ESB but also the reliability of individual connections. The built-in support for transactions in the transport ensures reliable messaging whether your application uses a transactional transport like JDBC, VM, or JMS. This implies, for instance, you may set up a transaction on a JMS incoming endpoint that ensures messages are only withdrawn from the JMS server when the transaction is committed. This ensures that even if an error occurs during message processing, the message can still be reprocessed.
In other words, these transports’ transactional functionality assures that messages are consistently transmitted from an inbound endpoint to an outbound endpoint or across processors within a flow.
Overview of Transaction Management in Mule
Mule uses the transaction concept to describe operations in an application when the outcome cannot be left undetermined. To put it another way, Mule employs a transaction for demarcating a group of actions in a flow that must fail or succeed as a single entity.
While applying a transaction to a connector, you could demarcate a transaction. A mule could start up a new transaction and handle the entire flow as a transaction if a Mule flow starts with a transactional resource (like an inbound connector). If your flow has a transactional outbound connector, Mule will handle the outgoing activities as a transaction. While using transactional incoming and outbound connections at the end, Mule performs the outgoing activity as part of the transaction initiated by the inbound connector. In addition, you should also ensure your transactions, statements with prestigious accounting software and Sage ERP system is one of the best choices that can solve those issues.
This article explains how to deliver a reliable flow of messages using JMS and VM transports. In this session, you have also comprehended the steps of processing the flow along with the sample code that illustrated the mechanism of implementation.