Do Try, Do Catch and Do Finally
If any EIP configuration is not available in the form, you can adjust it directly in the main.yaml file. To do this, go to the Source Code tab and edit the integration code.
|
The doTry EIP allows you to create integration flows by wrapping a process in a "Try" block. It creates doCatch and doFinally branches to handle specific exceptions and ensure certain actions are executed at the end, regardless of errors. This enables controlled failure handling, ensuring the flow execution continues without unnecessary interruptions.
Configuring the doTry EIP in the Diagram
To configure a doTry in an integration on the Diagram tab, follow these steps:
-
Click +Add Step on the canvas.
-
Select the EIPs tab.
-
Select the doTry EIP. You can use the search tool to locate it.
-
When adding the EIP to the canvas, three branches will be automatically created:
-
Empty Step: By clicking Add Step, you will add the EIP or component that will continue the flow. Only one branch of this type is allowed in the "Try" block.
-
doCatch: Captures and handles specific exceptions that may occur within the "Try" block. If there are multiple "doCatch" blocks, it executes the first exception that is caught.
-
You can enter one or more exceptions in the Exception field.
-
-
doFinally: This block is always executed, regardless of whether an exception occurred or not (even if there is no "doCatch" block). The "doFinally" branch will always be the last one on the right. Only one "doFinally" branch is allowed for each doTry EIP.
-
You can add additional "doCatch" branches by clicking "+" and then Add Handling Step. |
Deleting the doTry EIP and its branches
There are three scenarios for deleting the doTry EIP and its branches:
-
When deleting a "doCatch" block, all steps in that branch will be removed.
-
When deleting a "doFinally" block, all steps in that branch will be removed.
-
When deleting a doTry EIP, all subsequent blocks and steps will be removed.
Example
-
The flow starts with a timer, triggered every 60 seconds to query orders from an ERP.
-
The flow attempts to access the ERP to retrieve and process the orders using doTry. The order is then sent directly to the financial system, and the status is updated in the ERP.
-
If there are connection errors, such as ConnectException or SocketTimeoutException, these errors are caught with doCatch, logged and a notification is sent to the IT team.
-
Regardless of whether the flow succeeded or failed, the integration process is finalized with an audit record and a log generation using doFinally.
Check out the example in code format:
- from:
uri: timer:ConsultOrder
parameters:
period: 60000
steps:
- doTry:
id: doTry
steps:
- to: "http://erp.example.com/api/orders"
- log:
message: "Orders received: ${body}"
- setBody:
simple: "Processed orders: ${body}"
- to: direct:sendToFinance
- to: direct:updateERPStatus
doCatch:
- id: doCatch
exception:
- java.net.ConnectException
- java.net.SocketTimeoutException
steps:
- log:
message: "Failed to access ERP: ${exception.message}"
loggingLevel: ERROR
- to: direct:notifyError
doFinally:
id: doFinally
steps:
- log:
message: "Finalizing integration process - auditing"
- to: direct:registerAudit
Share your suggestions with us!
Click here and then [+ Submit idea]