Mule Concepts
Error Handling
Rollback Exception Strategy
• A rollback exception strategy can be used to ensure that a
message that throws an exception in a flow is rolled back for
reprocessing.
• A rollback exception strategy can be used when you
cannot correct an error when it occurs in a flow.
• A rollback exception strategy is normally used to handle errors
that occur in a flow that involve a transaction.
• If the transaction fails, that is, if a message throws an
exception while being processed, then the rollback exception
strategy rolls back the transaction in the flow.
• If the inbound connector is transactional, Mule delivers the
message to the inbound connector of the parent flow again to
reattempt processing (that is, message redelivery).
Rollback Exception Strategy
• When to use :
– To manage transactional errors.
– To manage unhandled exceptions—​exceptions that the application
fails to catch.
– Put in flows in which messages require redelivery.
• A rollback exception strategy has the potential to introduce an
infinite loop of activity within a flow.
• To avoid this infinite loop and responsibly manage
unresolvable errors, two limitations to a rollback exception
strategy can be applied:
– Define the maximum number of times that the rollback exception
strategy attempts to redeliver the message for processing.
– Define a flow to handle messages that exceed the maximum number
of redelivery attempts.
Rollback Exception Strategy
• When to use :
– To manage transactional errors.
– To manage unhandled exceptions—​exceptions that the application
fails to catch.
– Put in flows in which messages require redelivery.
• A rollback exception strategy has the potential to introduce an
infinite loop of activity within a flow.
• To avoid this infinite loop and responsibly manage
unresolvable errors, two limitations to a rollback exception
strategy can be applied:
– Define the maximum number of times that the rollback exception
strategy attempts to redeliver the message for processing.
– Define a flow to handle messages that exceed the maximum number
of redelivery attempts.
Rollback Exception Strategy
• A rollback exception strategy provides multiple attempts for a
message to successfully move through a flow before committing a
failed transaction and consuming the message, unlike catch
exception strategy.
• Mule attempts message redelivery when the flow uses one of the
following two types of transports:
– Transactional
• consumes a message as it travels through the flow
• transforms it to a different object, or enriches it with more data.
• When a message using a transactional transport throws an exception, a rollback
exception strategy rolls back the transaction so the transport can return a message
to its original state for reprocessing.
– Reliable
• does not consume a message as it travels through the flow until it can ascertain that
the message has successfully reached the end of the flow.
• When a message using a reliable transport throws an exception, the rollback
exception strategy discards the partially processed message and instructs the flow
to attempt processing the original message again.
Rollback Exception Strategy
• If the flow involves a reliable transport and a rollback
exception strategy, you must set the flow’s Processing
Strategy to "synchronous". (Configure the Processing Strategy
in the Flow Properties panel.)
• This is because reliable transports do not consume messages,
they wait for messages to successfully complete a flow before
consuming the messages; therefore, the flow must process
synchronously.
• If you deploy a Mule application that contains a flow with an
asynchronous processing strategy and a rollback exception
strategy configured for message redelivery, the application
fails!
Rollback Exception Strategy
– Transactional Transports :
• VM
– message rolls back to its original state for reprocessing.
• JDBC
– message rolls back to its original state for reprocessing.
• JMS
– message rolls back to its original state for reprocessing.
– Reliable Transports :
• JMS
– The session recovers, that is, Mule discards the copy of the source file and
attempts reprocessing the message using a fresh copy.
– A JMS redelivery configuration takes precedence over the rollback exception
strategy.
• FTP
– Mule discards the copy of the source file and attempts reprocessing the message
using a fresh copy.
• File
– Mule discards the copy of the source file and attempts reprocessing the message
using a fresh copy.
• IMAP
– Mule does not move the message from the mailbox and attempts reprocessing the message
using a fresh copy of the original.
Rollback Exception Strategy
• Unhandled Exceptions
– exceptions that they are unable to resolve by
performing corrective measures
– Typically, all unhandled exceptions are handled by
Mule’s default exception strategy
– But you can customize a rollback exception strategy to
more efficiently route messages with unhandled
exceptions.
– Below ways can be used :
• For one-way pattern of flow exchange, the rollback
exception strategy instructs the inbound connector transport
to execute corrective actions.
• For request-response pattern rollback exception strategy
changes the payload of a message and returns it to the
client.
Rollback Exception Strategy
• Rollback Exception Strategy vs. Default Exception
Strategy :
– Default Exception Strategy:
• Stores the exception information in the payload of the message.
• Returns null in the exceptionPayload attributeMessage.
• Injects NullPayload as the message’s payload; unable to customize.
• Records exception information in the exceptionPayload attribute;
unable to customize.
– Rollback Exception Strategy:
• Retains the information in the message payload at the time the
exception was thrown; does not alter the message payload.
• Stores the exception information in the exceptionPayload.
• Returns the message processing result during execution of the
exception strategy.
• Records exception information in the exceptionPayload attribute;
able to customize.
Rollback Exception Strategy
• Configuration properties :
– Display Name :
• A unique name for the rollback exception strategy in your application.
– Max redelivery attempts :
• an integer to define the number of times you want the rollback exception strategy to roll back a message for
reprocessing.
• Setting is as 0 : the rollback exception strategy does _*not* _attempt to redeliver the message and throws a
MessageRedeliveredException upon the first processing failure.
• Setting it as nothing : he rollback exception strategy redelivers the message over and over again, creating an
infinite loop.
– 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 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.
– Mule’s default exception strategy implicitly handles all exceptions which do not match the expression
you have defined in theWhen field.
• Enable Notifications:
– true (default)
» When set to true, instructs Mule to send an exception notification to a registered listener
– False
» To not to send the notification.
Rollback Exception Strategy

Mule error handling_rollback exception strategy

  • 1.
  • 2.
    • A rollbackexception strategy can be used to ensure that a message that throws an exception in a flow is rolled back for reprocessing. • A rollback exception strategy can be used when you cannot correct an error when it occurs in a flow. • A rollback exception strategy is normally used to handle errors that occur in a flow that involve a transaction. • If the transaction fails, that is, if a message throws an exception while being processed, then the rollback exception strategy rolls back the transaction in the flow. • If the inbound connector is transactional, Mule delivers the message to the inbound connector of the parent flow again to reattempt processing (that is, message redelivery). Rollback Exception Strategy
  • 3.
    • When touse : – To manage transactional errors. – To manage unhandled exceptions—​exceptions that the application fails to catch. – Put in flows in which messages require redelivery. • A rollback exception strategy has the potential to introduce an infinite loop of activity within a flow. • To avoid this infinite loop and responsibly manage unresolvable errors, two limitations to a rollback exception strategy can be applied: – Define the maximum number of times that the rollback exception strategy attempts to redeliver the message for processing. – Define a flow to handle messages that exceed the maximum number of redelivery attempts. Rollback Exception Strategy
  • 4.
    • When touse : – To manage transactional errors. – To manage unhandled exceptions—​exceptions that the application fails to catch. – Put in flows in which messages require redelivery. • A rollback exception strategy has the potential to introduce an infinite loop of activity within a flow. • To avoid this infinite loop and responsibly manage unresolvable errors, two limitations to a rollback exception strategy can be applied: – Define the maximum number of times that the rollback exception strategy attempts to redeliver the message for processing. – Define a flow to handle messages that exceed the maximum number of redelivery attempts. Rollback Exception Strategy
  • 5.
    • A rollbackexception strategy provides multiple attempts for a message to successfully move through a flow before committing a failed transaction and consuming the message, unlike catch exception strategy. • Mule attempts message redelivery when the flow uses one of the following two types of transports: – Transactional • consumes a message as it travels through the flow • transforms it to a different object, or enriches it with more data. • When a message using a transactional transport throws an exception, a rollback exception strategy rolls back the transaction so the transport can return a message to its original state for reprocessing. – Reliable • does not consume a message as it travels through the flow until it can ascertain that the message has successfully reached the end of the flow. • When a message using a reliable transport throws an exception, the rollback exception strategy discards the partially processed message and instructs the flow to attempt processing the original message again. Rollback Exception Strategy
  • 6.
    • If theflow involves a reliable transport and a rollback exception strategy, you must set the flow’s Processing Strategy to "synchronous". (Configure the Processing Strategy in the Flow Properties panel.) • This is because reliable transports do not consume messages, they wait for messages to successfully complete a flow before consuming the messages; therefore, the flow must process synchronously. • If you deploy a Mule application that contains a flow with an asynchronous processing strategy and a rollback exception strategy configured for message redelivery, the application fails! Rollback Exception Strategy
  • 7.
    – Transactional Transports: • VM – message rolls back to its original state for reprocessing. • JDBC – message rolls back to its original state for reprocessing. • JMS – message rolls back to its original state for reprocessing. – Reliable Transports : • JMS – The session recovers, that is, Mule discards the copy of the source file and attempts reprocessing the message using a fresh copy. – A JMS redelivery configuration takes precedence over the rollback exception strategy. • FTP – Mule discards the copy of the source file and attempts reprocessing the message using a fresh copy. • File – Mule discards the copy of the source file and attempts reprocessing the message using a fresh copy. • IMAP – Mule does not move the message from the mailbox and attempts reprocessing the message using a fresh copy of the original. Rollback Exception Strategy
  • 8.
    • Unhandled Exceptions –exceptions that they are unable to resolve by performing corrective measures – Typically, all unhandled exceptions are handled by Mule’s default exception strategy – But you can customize a rollback exception strategy to more efficiently route messages with unhandled exceptions. – Below ways can be used : • For one-way pattern of flow exchange, the rollback exception strategy instructs the inbound connector transport to execute corrective actions. • For request-response pattern rollback exception strategy changes the payload of a message and returns it to the client. Rollback Exception Strategy
  • 9.
    • Rollback ExceptionStrategy vs. Default Exception Strategy : – Default Exception Strategy: • Stores the exception information in the payload of the message. • Returns null in the exceptionPayload attributeMessage. • Injects NullPayload as the message’s payload; unable to customize. • Records exception information in the exceptionPayload attribute; unable to customize. – Rollback Exception Strategy: • Retains the information in the message payload at the time the exception was thrown; does not alter the message payload. • Stores the exception information in the exceptionPayload. • Returns the message processing result during execution of the exception strategy. • Records exception information in the exceptionPayload attribute; able to customize. Rollback Exception Strategy
  • 10.
    • Configuration properties: – Display Name : • A unique name for the rollback exception strategy in your application. – Max redelivery attempts : • an integer to define the number of times you want the rollback exception strategy to roll back a message for reprocessing. • Setting is as 0 : the rollback exception strategy does _*not* _attempt to redeliver the message and throws a MessageRedeliveredException upon the first processing failure. • Setting it as nothing : he rollback exception strategy redelivers the message over and over again, creating an infinite loop. – 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 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. – Mule’s default exception strategy implicitly handles all exceptions which do not match the expression you have defined in theWhen field. • Enable Notifications: – true (default) » When set to true, instructs Mule to send an exception notification to a registered listener – False » To not to send the notification. Rollback Exception Strategy