JBoss Fuse
Error handling
Christina Lin
JBoss Technology Evangelist
clin@redhat.com
RED HAT CONFIDENTIAL | ADD NAME2
Irrecoverable
Recoverable
Error Handling PROBLEM!!!
Unstable network?
Messaging queue full
Incorrect ID data format
Name not found
RED HAT CONFIDENTIAL | ADD NAME3
Error Handling
Recoverable
•  Errors can be reprocessed
•  Problem will go away in time
•  Exception
•  Stores in Exchange
Irrecoverable
•  Errors cannot be reprocessed
•  Problem stays the same
•  Fault Flag
•  Stores in Out Message in Exchange
exchange.getOut().setFault(true);
exchange.getOut().setBody(”err");
RED HAT CONFIDENTIAL | ADD NAME4
Error Handling
Error
Handler
On
Exception
Try
Catch
Finally
<errorHandler id=”errHandler”
type="DefaultErrorHandler”>
</errorHandler>
<onException>
<exception>
java.io.IOException</exception>
<exception>
java.io.SQLException</exception>
<onException>
<doTry>
<process ref="processorFail"/>
<to uri="mock:result"/>
<doCatch>
<exception>java.io.IOException</exception>
<to uri="mock:catch"/>
</doCatch>
<doFinally>
<to uri="mock:finally"/>
</doFinally>
</doTry>
RED HAT CONFIDENTIAL | ADD NAME5
Redelivery
Settings
MaximumRedeliveries
RedeliveryDelay
BackOffMultiplier
CollisionAvoidanceFactor
MaximumRedeliveryDelay
DelayPattern
AsyncDelayedRedelivery
Maximum number
of redelivery
attempts allowed.
Delay between
each redelivery
(ms)
Asynchronous
delayed redelivery
or not?
Exponential
backoff
multiplier used
in each delay
Eg.
1000, 1000x2,
10000x2x2
percentage to use when
calculating a random delay offset
An upper bound for redelivery
delay
Pattern for calculating delay
0:1000;3:500;10;100
RED HAT CONFIDENTIAL | ADD NAME6
Exception Policy
<redeliveryPolicy maximumRedeliveries="5"
retryAttemptedLogLevel="WARN"
backOffMultiplier="2"
useExponentialBackOff="true"/>
Recoverable Errors
<errorHandler id=”errHandler”
type="DefaultErrorHandler”>
<onException>
<exception>
java.io.IOException</exception>
<exception>
java.io.SQLException</exception>
RED HAT CONFIDENTIAL | ADD NAME7
Error Handlers and Scope
Camel Context
Route
Route
Route
Error Handler
On Exception
Error Handler
On Exception
Try n Catch
DefaultError
Handler
LoggingErro
rHandler
NoErrorHan
dler
DeadLetter
Channel
Error Handler
Camel Context Scope
Camel Route Scope
RED HAT CONFIDENTIAL | ADD NAME8
Error Handler
DefaultErrorHandler
Default
one
Log
<errorHandler
id=”errHandler”
type="DefaultErrorHandler”/>
RED HAT CONFIDENTIAL | ADD NAME9
Error Handler
DeadLetterChannel
Log
Dead
Letter
Channel
Queue
Database
Log
File
Option to put
Original Message
<errorHandler
id=”errHandler”
type="DeadLetterChannel”
deadLetterUri=“amq:queue:DLQ"/>
RED HAT CONFIDENTIAL | ADD NAME10
On Exception
Default Error Handler
java.lang.Exception
java.lang.IOException
java.lang.FileNotFoundException
FileNotFoundException
redeliveryDelay = 3000
redeliveryDelay = 5000
Delay = 5000
Retry = 3
MyException
redeliveryDelay = 2000
Delay = 2000
Retry = 3
maximumRedeliveries= 3
Not Handled
RED HAT CONFIDENTIAL | ADD NAME11
Try.. Catch.. Finally
doTry
doCatch
doCatch
doCatch
Process Process
Exception Exception
Exception
Handled = falseException
onWhen
Return exception to
beginning (Caller)
Add more condition
to the exception
condition
onRedeliver
retryWhile
Catch multiple
Exceotion
RED HAT CONFIDENTIAL | ADD NAME12
Try.. Catch.. Finally
<route>
<from uri="direct:start"/>
<doTry>
<process ref="processorFail"/>
<to uri="mock:result"/>
<doCatch>
<exception>java.io.IOException</exception>
<handled><constant>false</constant></handled>
<to uri="mock:io"/>
</doCatch>
<doCatch>
<exception>java.io.IOException</exception>
<onWhen><simple>${exception.message} contains 'Damn'</simple></onWhen>
<to uri="mock:catch"/>
</doCatch>
<doCatch>
<exception>java.lang.Exception</exception>
<to uri="mock:error"/>
</doCatch>
</doTry>
</route>
Just like Java
RED HAT CONFIDENTIAL | ADD NAME13
Error Handler Exercise
Stock
purchase
XML
XML
XSD
Schema
orderdata
Catch the
validate
exception
garbage
Next step
RED HAT CONFIDENTIAL | ADD NAME14
Error Handler Exercise
XML
Random Exceptions
Retry if failed
DLQ
Data

JBoss Fuse - Fuse workshop Error Handling

  • 1.
    JBoss Fuse Error handling ChristinaLin JBoss Technology Evangelist clin@redhat.com
  • 2.
    RED HAT CONFIDENTIAL| ADD NAME2 Irrecoverable Recoverable Error Handling PROBLEM!!! Unstable network? Messaging queue full Incorrect ID data format Name not found
  • 3.
    RED HAT CONFIDENTIAL| ADD NAME3 Error Handling Recoverable •  Errors can be reprocessed •  Problem will go away in time •  Exception •  Stores in Exchange Irrecoverable •  Errors cannot be reprocessed •  Problem stays the same •  Fault Flag •  Stores in Out Message in Exchange exchange.getOut().setFault(true); exchange.getOut().setBody(”err");
  • 4.
    RED HAT CONFIDENTIAL| ADD NAME4 Error Handling Error Handler On Exception Try Catch Finally <errorHandler id=”errHandler” type="DefaultErrorHandler”> </errorHandler> <onException> <exception> java.io.IOException</exception> <exception> java.io.SQLException</exception> <onException> <doTry> <process ref="processorFail"/> <to uri="mock:result"/> <doCatch> <exception>java.io.IOException</exception> <to uri="mock:catch"/> </doCatch> <doFinally> <to uri="mock:finally"/> </doFinally> </doTry>
  • 5.
    RED HAT CONFIDENTIAL| ADD NAME5 Redelivery Settings MaximumRedeliveries RedeliveryDelay BackOffMultiplier CollisionAvoidanceFactor MaximumRedeliveryDelay DelayPattern AsyncDelayedRedelivery Maximum number of redelivery attempts allowed. Delay between each redelivery (ms) Asynchronous delayed redelivery or not? Exponential backoff multiplier used in each delay Eg. 1000, 1000x2, 10000x2x2 percentage to use when calculating a random delay offset An upper bound for redelivery delay Pattern for calculating delay 0:1000;3:500;10;100
  • 6.
    RED HAT CONFIDENTIAL| ADD NAME6 Exception Policy <redeliveryPolicy maximumRedeliveries="5" retryAttemptedLogLevel="WARN" backOffMultiplier="2" useExponentialBackOff="true"/> Recoverable Errors <errorHandler id=”errHandler” type="DefaultErrorHandler”> <onException> <exception> java.io.IOException</exception> <exception> java.io.SQLException</exception>
  • 7.
    RED HAT CONFIDENTIAL| ADD NAME7 Error Handlers and Scope Camel Context Route Route Route Error Handler On Exception Error Handler On Exception Try n Catch DefaultError Handler LoggingErro rHandler NoErrorHan dler DeadLetter Channel Error Handler Camel Context Scope Camel Route Scope
  • 8.
    RED HAT CONFIDENTIAL| ADD NAME8 Error Handler DefaultErrorHandler Default one Log <errorHandler id=”errHandler” type="DefaultErrorHandler”/>
  • 9.
    RED HAT CONFIDENTIAL| ADD NAME9 Error Handler DeadLetterChannel Log Dead Letter Channel Queue Database Log File Option to put Original Message <errorHandler id=”errHandler” type="DeadLetterChannel” deadLetterUri=“amq:queue:DLQ"/>
  • 10.
    RED HAT CONFIDENTIAL| ADD NAME10 On Exception Default Error Handler java.lang.Exception java.lang.IOException java.lang.FileNotFoundException FileNotFoundException redeliveryDelay = 3000 redeliveryDelay = 5000 Delay = 5000 Retry = 3 MyException redeliveryDelay = 2000 Delay = 2000 Retry = 3 maximumRedeliveries= 3 Not Handled
  • 11.
    RED HAT CONFIDENTIAL| ADD NAME11 Try.. Catch.. Finally doTry doCatch doCatch doCatch Process Process Exception Exception Exception Handled = falseException onWhen Return exception to beginning (Caller) Add more condition to the exception condition onRedeliver retryWhile Catch multiple Exceotion
  • 12.
    RED HAT CONFIDENTIAL| ADD NAME12 Try.. Catch.. Finally <route> <from uri="direct:start"/> <doTry> <process ref="processorFail"/> <to uri="mock:result"/> <doCatch> <exception>java.io.IOException</exception> <handled><constant>false</constant></handled> <to uri="mock:io"/> </doCatch> <doCatch> <exception>java.io.IOException</exception> <onWhen><simple>${exception.message} contains 'Damn'</simple></onWhen> <to uri="mock:catch"/> </doCatch> <doCatch> <exception>java.lang.Exception</exception> <to uri="mock:error"/> </doCatch> </doTry> </route> Just like Java
  • 13.
    RED HAT CONFIDENTIAL| ADD NAME13 Error Handler Exercise Stock purchase XML XML XSD Schema orderdata Catch the validate exception garbage Next step
  • 14.
    RED HAT CONFIDENTIAL| ADD NAME14 Error Handler Exercise XML Random Exceptions Retry if failed DLQ Data