Load Balanced Endpoints

When you use Load Balanced API Endpoints, the traffic that comes to the resource is routed to the mentioned endpoint addresses based on the round-robin algorithm. You can enable load balancing capabilities with Choreo Connect (CC) when working with the following two WSO2 products.

Load Balanced Endpoints with APIM

Important

Currently WSO2 API Manager allows to add load balanced endpoints only to the API level.

Step 1 - Define the Load Balanced Endpoints in the Publisher

After creating an API in the APIM publisher, select the API you want to apply load balanced capability.

  1. Click Develop -> API Configurations -> Endpoints.

    1. Under the Load balanced and Failover Configurations and select the endpoint type as Load Balanced.

    2. Provide the service URLs that you want to handle load balancing.

    Info

    Click the + sign in the text box after adding each service URL to provide multiple service endpoints.

    Add load balanced endpoints in APIM

    Add load balanced endpoints addition in APIM

  2. Click Save & Deploy.

Step 2 - Invoke API Endpoint Via The Choreo Connect.

After obtaining a valid JWT token, you can invoke APIs as described here.

Example is given below:

curl -k -X GET "https://localhost:9095/pizzashack/1.0.0/menu" -H "accept: application/json" -H "Authorization: Bearer <COPIED_TOKEN>"

Load Balanced Endpoints With APICTL

In this approach you can define load balanced endpoints in API level as well as in resource level. Below section demonstrates how load balanced endpoints in those two levels.

Step 1 - Define Load Balanced Endpoints In The OpenAPI Definition file.

Load Balanced Endpoints In API Level

Below section demonstrates how to define load balanced endpoints for API level in an OpenAPI definition file.

openapi: <version>
...
x-wso2-production-endpoints:
  urls:
    - <URL1>
    - <URL2>
  type: load_balance
...
...
x-wso2-production-endpoints:
  urls:
    - http://localhost:2380/v2
    - http://localhost:2381/v2
  type: load_balance
...

Load Balanced Endpoints In Resource Level

Below section demonstrates how to define load balanced endpoints for resource level in an Open API definition file.

openapi: <version>
...
paths:
  "/<path>":
    <operation>:
    x-wso2-production-endpoints:
    urls:
      - <URL1>
      - <URL2>
    type: load_balance
paths:
  "/pet/findByStatus":
    get:
      responses:
        '200':
          description: OK
    ...
    x-wso2-production-endpoints:
    urls:
      - http://localhost:2380/v1
      - http://localhost:2380/v1
    type: load_balance
  "/pet/{petId}":
    get:
      responses:
        '200':
          description: OK
...

Step 2 - Deploy the API Project And Invoke With Load Balanced Endpoints

After defining an API in the OpenAPI definition file, deploy it in Choreo Connect.

Top