Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Call other microservices

Gustavo Denis edited this page Oct 31, 2019 · 1 revision
Main > Using Liquid for building your application > Call other microservices

Even though microservices are design so as to deal with highly cohesive and loosely coupled logic and data, they eventually are going to call each other.

Take a look at related key concepts of Liquid
Business Error Handling
REST API as (formal) Object Model
Microservice Sizing

#Synchronously (via REST)

The most simple way for a microservice call other microservice is calling the other's REST API.

This lowers the resiliency of the whole system, however, since it creates cascading failure scenarios where errors from the called microservice reverberates in the caller one and so on.

For doing this type of call, anyway, Liquid provides the LightApi service as bellow.

var orderDraft = await new LightApi("ORDER").PutAsync<OrderVM>("/draftfrombasket", basket);
See how this is done in Liquid Hotel360 sample application.

#Asynchronously (via Message Bus)

For the best of scalability and resiliency, it is recommended to make asynchronous calls between microservices through a Message Bus whenever the business logic allows it - that is, whenever the business logic is naturally asynchronous.

Such messages are then processed by the called microservice as its public asynchronous API.

await new MessageBus<AzureServiceBus>("SHOP", "generate_order_draft").SendToQueue(basketMessage)

| See how this is done in Liquid Hotel360 sample application.|

##Polly As when implementing retries, the recommended approach for circuit breakers is to take advantage of proven .NET libraries like Polly. Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Circuit Breaker.

Add Polly (bot) to your team.(https://github.com/App-vNext/Polly)

To use the Polly framework, add the code above on the Startup class

app.UsePolly();

Case the startup command is not added, Liquid will initialize the Workbench without Polly features.

##LightApi.cs Add Polly policy in the appsettings.json of the microservice in use

"Retry" means the number of times to retry connect with the microservice "Wait" means the seconds to wait before retry again. "IsBackOff" defines where the delays between attempts increase with the number of failures.

 "LightAPI": {
    "Basket": {
      "Host": "http://localhost",
      "Port": "59034",
      "Suffix": "api/v1",
      "Telemetry": true,
      "Polly": {
        "Retry": 10,
        "IsBackOff": true,
        "Wait": 0
      }
    }
  }, 

To use the Polly framework from Liquid use Liquid.Microservices.Runtime namespace.

##The Backend For Frontend

The BFF is tightly coupled to a specific user experience, and will typically be maintained by the same team as the user interface, thereby making it easier to define and adapt the API as the UI requires, while also simplifying process of lining up release of both the client and server components.

|:---|

Clone this wiki locally