Tuesday, August 11, 2015

Exception/Error Handling in WSO2 ESB Endpoint

When we create a service in ESB this needs to be send to a particular end point, in transport layer it might be possible that any error can come so it is necessary to handle this situation wherever an error occurred.

If the end point is not available or due to any firewall issue by which connection time out may occur then your message will be lost. Therefore to overcome from this situation error handling is required.

In endpoint configure for error handling can have below three states.

  • Active: End point is up and ready to handle request.
  • Timeout: An error has come but still message is received. It will keep on receiving message until maximum retries. If it keeps on failing then it will go to suspended state.
  • Suspended: In this state message can’t be received or sent and endpoint result will go in fault. ESB waits until the initial duration to be passed by default it is 30 second. In between if any request gets succeeded then it will go to Active state else in timeout error. ESB waits before retrying messages using the following formula:
Min(current suspension duration * progressionFactor, maximumDuration)


Example:

<endpoint name="EmployyeDetails_EPR">
<address uri="http://XXXX:9773/services/getEmployeeDetails">
<timeout>
<duration>30000</duration>
</timeout>
<markForSuspension>
<errorCodes>101504, 101505</errorCodes>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<retryDelay>1</retryDelay>
</markForSuspension>
<suspendOnFailure>
<errorCodes>101500, 101501, 101506, 101507, 101508</errorCodes>
<initialDuration>3000</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
</address>
</endpoint>



Timeout Setting

Name
Values
Default
Description
duration
Miliseconds
60000
If within 60 second response does not come then it will go to timeout state
responseAction
discard, fault, none
none
On failure It checks whether message needs to be discarded or need to go in exception handling state
MarkForSuspension State


Name
Values
Default
Description
errorCodes
Comma separated list of error codes
101504, 101505
101504: shows the connection timeout error 101505: connection closed
retriesBeforeSuspension
Integer
0
It shows how many time it can retry to send message
retryDelay
milliseconds
0
wait time between the last retry  and the next retry.

SuspensionOnFailure State

Name
Values
Default
Description
errorCodes
Comma separated error codes
All the errors except the errors specified inmarkForSuspension
Errors that send the endpoint into the "Suspended" state.
initialDuration
milliseconds
30000
This is the default time after this time retry will occur
progressionFactor
Integer
1
The endpoint will try to send the messages after the initialDuration. If it still fails, the next duration is calculated as:
Min(current suspension duration * progressionFactor, maximumDuration)
maximumDuration
milliseconds
Long.MAX_VALUE
Upper bound of retry duration.