Tuesday, July 7, 2015

Configuring timeouts with WSO2 ESB

When dealing with proxies/sequences built in wso2 ESB, a common case is if the BE service is not responding for a long time time outs occurs.  So you may need to show some reasonable error logs to a customer on such timeouts.  What you can do is configure a timeout and add an onError fault sequence to be executed.

Let us look at following sample.

            <address uri="http://localhost:9000/services/SimpleStockQuoteService">

         This is an endpoint declaration in a sample proxy, and i'm setting an endpoint timeout of 10 seconds for it. By setting the responseAction property to fault, on timeout it will invoke the fault sequence defined.  markForSuspension tag basically directly marks this endpoint as suspended if the provided errorCode (errors) occur. suspendFailure tag option can be configured so that when certain error code based error occurs, you can retry those requests before sending the endpoint to suspended state. You can gain more insight on this by going through [1].

The point I need to bring out here is , if you need to set the timeout to happen for something less than 15 seconds. In practice such a small timeout is not recommended because a normal endpoint callback would at least take 30 seconds. But in a situation where you need to update the endpoint to timeout in within a small time limit, you need to remember to configure following values.

There is a TimeoutHandler that is executed in an interval of 15 seconds. So the time the callbacks get cleared , can be deviated up to 15
seconds from the value you configure as endpoint timeout(in your proxy configuration). So say that you declare your endpoint timeout as 10 seconds, this will only be taken into count after this initial 15 seconds interval. So if you need it to timeout within 10 seconds , you have to declare following properties as well.  

(These files can be found in repository/conf)
http.socket.timeout=30000  (passthru-http.properties- depending on your transport type this can be nhttp.properties)
synapse.global_timeout_interval=20000 (synapse.properties)
synapse.timeout_handler_interval=5000 (synapse.properties)
<duration>10000</duration> ( in your proxy configuration)

The values should be configured that duration <= http.scoket.timeout .  You can go through [2] to gain more info on this.

[1] https://docs.wso2.com/display/ESB481/Endpoint+Error+Handling



No comments:

Post a Comment