Thursday, May 18, 2017

Handling server side issues of integration endpoints with Ballerina

Routing invocations to a backend service or chaining a bunch of services together is a common integration requirement. In such scenarios you will have to mitigate the risk of unpredictability integrating over disparate systems brings into the mix. One common way of address this risk is to utilize HTTP status codes. Ballerina makes dealing with status codes easy with the following methods found in the package,
  • getStatusCode
  • setStatusCode  
Refer to the API documentation for mode details on the methods:

The example below shows how getStatusCode method can be used to make invocation time decisions on an endpoint’s availability and act accordingly. Similarly, you can utilize received status codes of HTTP endpoints as an effective way of hardening your program when it’s appropriate.

To try out the example create the folder structure <BALLERINA_HOME>/statuscode/sample and then create ballerina files with the content of the two gists. Package the services into a bsz archive and run it. Invoke /proxy service with a header "CONTROLLER: faulty backend" to simulate an server side error.

curl -X GET -v http://localhost:9090/proxy -H "CONTROLLER: faulty backend"

find out more about ballerina here:

Note: this example was written for ballerina 0.86 and may not work with other versions.

No comments:

Post a Comment