Micro Services

A key philosophy of GoCollaborate is to provide the minimum feature-integrated package that could well sustain the common business in most cloud computing scenarios. Microservices, as an indispensable part for server clustering and services management, is also included as a built-in module. This tutorial will walk you through the common usage of Coordinator in service registration, service discovery, service query and its load balancing policy.

Configuration

Before getting started, we need to launch up the server in Coordinator mode.

In main.go, we create a simple script running the server by its default arguments:

package main

import (
    "github.com/GoCollaborate/src"
)

func main() {
    collaborate.Run()
}

Next, start the server by running:

go run main.go -mode=cdnt -port=8081

Services Registration

Service registration is automatically done during the start-up period of each Collaborator, please follow the QuickStart turorial to start a Collaborator cluster, and don't forget to change its configuration in which it points to the corresponding net address of the Coordinator.

Edit case.json to:

{
    // ...
    "coordinator": {
        "ip": "localhost",
        "port": 8081,
        "alive": true
    }
}

The services list is now available at /v1/services by sending GET request.

Service Configuration

To inspect the current service list:

  • GET /v1/services

To inspect the current services provided by a specific cluster:

  • GET /v1/cluster/{id}/services

To register a set of new services:

  • POST /v1/services
    • Example request:
      {
        "data":[{
            "type":"service",
            "attributes":{
                "description":"The description of your service",
                "methods":["GET","POST","PUT","DELETE"],
                "parameters":[...<Parameter>],
                "registers":[],
                "subscribers":[],
                "mode":"LBMobdeRoundRobin",
                "dependencies":[],
                "version":"1.0",
                "platform_version":"golang1.8.1"
            }
        }]
      }
      
    • Example response:
      {
        "data":[{
            "id": "service_id",
            "type":"service",
            "attributes":{
                "service_id": "service_id",
                "description":"The description of your service",
                "methods":["GET","POST","PUT","DELETE"],
                "parameters":[...<Parameter>],
                "registers":[],
                "subscribers":[],
                "mode":"LBMobdeRoundRobin",
                "dependencies":[],
                "version":"1.0",
                "platform_version":"golang1.8.1"
            }
        }]
      }
      

To update a set of existing services:

  • PUT /v1/services
    • Example request:
      {
        "data":[{
            "id": "service_id",
            "type":"service",
            "attributes":{
                "service_id": "service_id",
                "description":"The updated description of your service",
                "methods":["GET","POST"],
                "parameters":[...<Parameter>],
                "registers":[],
                "subscribers":[],
                "mode":"LBMobdeRoundRobin",
                "dependencies":["dependent_service_id"],
                "version":"1.0",
                "platform_version":"golang1.8.1"
            }
        }]
      }
      
    • Example response:
      {
        "data":[{
            "id": "service_id",
            "type":"service",
            "attributes":{
                "service_id": "service_id",
                "description":"The updated description of your service",
                "methods":["GET","POST"],
                "parameters":[...<Parameter>],
                "registers":[],
                "subscribers":[],
                "mode":"LBMobdeRoundRobin",
                "dependencies":["dependent_service_id"],
                "version":"1.0",
                "platform_version":"golang1.8.1"
            }
        }]
      }
      

To register a set of providers for a service:

  • POST /v1/services/{id}/registry
    • Example request:
      {
        "data":[{
            "type":"registry",
            "attributes": <Card>
        },{
            "type":"registry",
            "attributes": <Card>
        },{
            "type":"registry",
            "attributes": <Card>
        }]
      }
      
    • Example response:
      {
        "data":[{
            "id": "full_endpoint",
            "type":"registry",
            "attributes": <Card>
        },{
            "id": "full_endpoint",
            "type":"registry",
            "attributes": <Card>
        },{    
            "id": "full_endpoint",
            "type":"registry",
            "attributes": <Card>
        }]
      }
      

To notify a set of subscribers of a service:

  • POST /v1/services/{id}/subscription
    • Example request:
      {
        "data":[{
            "type":"subscription",
            "attributes":{}
        },{
            "type":"subscription",
            "attributes":{}
        },{
            "type":"subscription",
            "attributes":{}
        }]
      }
      
    • Example response:
      {
        "data":[{
            "id": "random_token_id",
            "type":"subscription",
            "attributes":{}
        },{
            "id": "random_token_id",
            "type":"subscription",
            "attributes":{}
        },{
            "id": "random_token_id",
            "type":"subscription",
            "attributes":{}
        }]
      }
      

Service Query

[TO BE CONTINUE...]

Load Balancing Policy

[TO BE CONTINUE...]



results matching ""

    No results matching ""