STUDIO Visual Editor
-
From the Error Handling palette group, drag and drop the Rollback Exception Strategy icon 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 Req’d Value Display Name
x
A unique name for the rollback exception strategy in your application.
Max redelivery attempts
x
Enter 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.If you enter nothing in the Max redelivery attempts field (i.e. leave the field blank), the rollback exception strategy will redeliver 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
. =D===When
Enter an expression to indicate the kind of exception the rollback exception should handle.
• 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
#[exception.causedBy(org.mule.example.AlreadyProcessedException)]
,
only those messages which throw anorg.mule.example.AlreadyProcessedException
exception are handled by this exception strategy. Mule’s default exception strategy implicitly handles all exceptions which do not match the expression you have defined in the When field.Enable Notifications
true (default)
false
When set to true, 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.
What follows are some 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 (a.k.a. “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 Req’d Value doc:name
x
A unique name for the rollback exception strategy in your application.
Not required in Standalone.maxRedeliveryAttempts
x
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. • 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
#[exception.causedBy(org.mule.example.AlreadyProcessedException)]
, only those messages which throw anorg.mule.example.AlreadyProcessedException
exception are handled by this exception strategy. Mule’s default exception strategy implicitly handles all exceptions which do not match the expression you have defined in the when attribute.enableNotifications
true (default)
false
When set to true, Mule to send an exception notification to a registered listener — say, the Mule Management Console — whenever the catch exception strategy accepts handles an exception.
What follows are some 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. |