Studio Visual Editor
-
Search for and drag and drop the Rollback Exception Strategy icon to put into the footer bar of a flow.
-
Open the Rollback Exception Strategy’s Properties Editor, then configure the attributes according to the table below.
Field Value Display Name
(Required) A unique name for the rollback exception strategy in your application.
Max redelivery attempts
(Required) Enter an integer to define the number of times you want the rollback exception strategy to roll back a message for reprocessing. If you set the default value to
0
, the rollback exception strategy does _*not* _attempt to redeliver the message and throws a MessageRedeliveredException upon the first processing failure.If you enter nothing in the Max redelivery attempts field (leave the field blank), the rollback exception strategy redelivers the message over and over again, creating an infinite loop. Refer to Configuring Redelivery Attempts in JMS Global Connector below to learn more about setting this value to 0
.When
Enter an expression to indicate the kind of exception the rollback exception should handle.
Conditions for this field:
-
Expression not defined: All messages in this flow that throw exceptions are handled by this rollback exception strategy.
-
Expression defined: When Mule evaluates the expression against the message being processed and returns true, Mule executes the exception strategy. For example, if you enter the following, only those messages which throw an
org.mule.example.AlreadyProcessedException
exception are handled by this exception strategy:
#[exception.causedBy(org.mule.example.AlreadyProcessedException)]
,Mule’s default exception strategy implicitly handles all exceptions which do not match the expression you have defined in the When field.
Enable Notifications
Checked (default). When checked, instructs Mule to send an exception notification to a registered listener — for example, the Mule Management Console — whenever a message throws an exception in this flow.
Log Exceptions
Checked (default). When checked, instructs Mule to log the exceptions.
Here are examples of expressions that you can enter in the When field:
#[exception.causedBy(org.mule.example.ExceptionType)] #[exception.causedExactlyBy(org.mule.example.ExceptionType)] #[exception.causeMatches(org.mule.example.*)] #[exception.causeMatches(*) && + !exception.causedBy(java.lang.ArithmeticException) && + !exception.causedBy(org.mule.api.registry.ResolverException)]
-
-
Drag building blocks from the palette into the Rollback Exception Strategy box to build a flow that processes messages that throw exceptions in the parent flow. A rollback exception strategy can contain any number of message processors.
If your flow uses a reliable transport, you can stop at this point and not configure a redelivery exhausted sub flow. If you choose not to configure a redelivery exhausted sub flow:
-
A message that exceeds its redelivery attempts (called "a poisoned message") throws a MessageRedeliveredException.
-
The exception strategy commits the transaction.
-
The exception strategy consumes the message.
-
-
Drag building blocks from the palette into the redelivery exhausted box to build a flow that processes messages which exceed the maximum number of redelivery attempts. For example, you may wish to use redelivery exhausted to direct all “poisoned messages” to a dead letter queue. A redelivery exhausted flow can contain any number of message processors.
You can define only one exception strategy for each flow. If you need to design a more complex error handling strategy that involves more than one way of handling exceptions, consider using a Choice Exception Strategy. |
XML Editor or Standalone
-
In your flow, below all the message processors, add a
rollback-exception-strategy
element. Refer to code below. -
Configure attributes of the exception strategy according to the table below.
Attribute Value doc:name
(Required) A unique name for the rollback exception strategy in your application.
Not required in Standalone.maxRedeliveryAttempts
(Required) Use an integer to define the number of times you want the rollback exception strategy to rollback a message for reprocessing. If you set the default value to
0
, which means the rollback exception strategy will _not _attempt to redeliver the message and will throw a MessageRedeliveredException upon the first processing failure. Refer to Configuring Redelivery Attempts in JMS Global Connector below to learn more about setting this value to0
.when
Define an expression to indicate the kind of exception the rollback exception should handle.
Conditions for this field:
-
Expression not defined: all messages in this flow that throw exceptions will be handled by this rollback exception strategy.
-
Expression defined: when Mule evaluates the expression against the message being processed and returns true, Mule executes the exception strategy. For example, if you enter the following, only those messages which throw an
org.mule.example.AlreadyProcessedException
exception are handled by this exception strategy:
#[exception.causedBy(org.mule.example.AlreadyProcessedException)]
,
Mule’s default exception strategy implicitly handles all exceptions which do not match the expression you have defined in the when attribute.
enableNotifications
Checked (default). When checked, instructs Mule to send an exception notification to a registered listener — for example, the Mule Management Console — whenever a message throws an exception in this flow.
logExceptions
Checked (default). When checked, instructs Mule to log the exceptions.
<rollback-exception-strategy maxRedeliveryAttempts="0" doc:name="My Rollback Exception Strategy" when="exception.causedBy(org.mule.example.ExceptionType)" enableNotifications="true"/>
Here are examples of expressions that you can enter in the When field:
#[exception.causedBy(org.mule.example.ExceptionType)] #[exception.causedExactlyBy(org.mule.example.ExceptionType)] #[exception.causeMatches(org.mule.example.*)] #[exception.causeMatches(*) && + !exception.causedBy(java.lang.ArithmeticException) && + !exception.causedBy(org.mule.api.registry.ResolverException)]
-
-
Add child elements to your
rollback-exception-strategy
to build a flow that processes messages that throw exceptions in the parent flow. A rollback exception strategy can contain any number of message processors.If your flow uses a reliable transport, you can stop at this point and not configure a redelivery exhausted sub flow. If you choose not to configure a redelivery exhausted sub flow:
-
A message that exceeds its redelivery attempts (a.k.a. “a poisoned message”) throws a
MessageRedeliveredException
. -
The exception strategy commits the transaction.
-
The exception strategy consumes the message.
-
-
Add an
on-redelivery-attempts-exceeded
child element to yourrollback-exception-strategy
element at the bottom, below all the message processors included in the exception strategy. -
Add child elements to your
on-redelivery-attempts-exceeded
child element to build a flow that processes messages which exceed the maximum number of redelivery attempts. For example, you may wish to use redelivery exhausted to direct all “poisoned messages” to a dead letter queue. A redelivery exhausted flow can contain any number of message processors.You can define only one exception strategy for each flow. If you need to design a more complex error handling strategy that involves more than one way of handling exceptions, consider using a Choice Exception Strategy.