Apache Dubbo-go

repository·main·Indexed 26 days ago

https://github.com/apache/dubbo-go

A high-performance RPC and microservice framework for Golang, compatible with other Dubbo language implementations. It provides service governance features including service discovery (Nacos, Zookeeper, Etcd, Polaris-mesh), load balancing, traffic management, and observability via Prometheus and OpenTelemetry. The framework supports the Triple protocol and includes development tools such as dubbogo-cli, protoc-gen-go-triple, and dubbo-go-schema for configuration validation.

Tokens
13K
Snippets
31
Records
131
Agent score
86%

What's inside apache-dubbo-go

  1. Dubbo-go Features and Capabilities

    main

    Dubbo-go offers the following service governance capabilities:

    • RPC Protocols: Triple, gRPC compatible, and HTTP-friendly.
    • Service Discovery: Nacos, Zookeeper, Etcd, Polaris-mesh.
    • Load Balance: Adaptive, Random, RoundRobin, LeastActive, ConsistentHash.
    • Traffic Management: Traffic split, timeout, rate limiting, canary release.
    • Configuration: YAML files and dynamic configuration (Nacos, Apollo, Zookeeper, etc.).
    • Observability: Metrics (Prometheus), tracing (OpenTelemetry v1.21.0+), and logging.
    • HA Strategy: Failover, Failfast, Failsafe/Failback, Available, Broadcast, Forking.
    • Interoperability: Full compatibility with Apache Dubbo (Java) via Triple protocol generic calls, group/version wildcard matching, and TLS API redesign.
  2. Generate Triple Go bindings with protoc

    main

    Use the protoc compiler with the protoc-gen-go-triple plugin to generate Go language bindings for Dubbo services. You must set both --go_out=. and --go-triple_out=. and define the file generation path in your .proto file using the go_package option.

    protoc --go_out=. --go_opt=paths=source_relative --go-triple_out=. your_file.proto
  3. Install Dubbo-go

    main

    To install Dubbo-go, use the following Go command to fetch the latest version of the v3 series:

    go get dubbo.apache.org/dubbo-go/v3@latest

    Prerequisites:

    • Go 1.24 or higher is required for optimal performance and compatibility.
  4. Debug Dubbo protocol interfaces with dubbogo-cli

    main

    To debug services using the Dubbo protocol, you must define your request and response bodies in JSON files.

    JSON Format Requirements:

    • Keys must match the Go struct field names (e.g., ID, Name).
    • Values follow the pattern type@val (e.g., string@A000, bool@true, int@18).
    • Every struct (including nested ones) must include a JavaClassName field that matches the server-side implementation exactly.

    Command Syntax:

    ./dubbo-go-cli -h=<host> -p=<port> -proto=dubbo -i=<interface_name> -method=<method_name> -sendObj="<request_json_path>" -recvObj="<response_json_path>"
    # Example request JSON (userCall.json)
    {
      "ID": "string@A000",
      "Male": "bool@true",
      "SubInfo": {
        "SubID": "string@A001",
        "SubMale": "bool@false",
        "SubAge": "int@18",
        "JavaClassName":"string@com.ikurento.user.SubInfo"
      },
      "JavaClassName": "string@com.ikurento.user.CallUserStruct"
    }
    
    # Execution command
    ./dubbo-go-cli -h=localhost -p=20001 -proto=dubbo -i=com.ikurento.user.UserProvider -method=GetUser -sendObj="./userCall.json" -recvObj="./user.json"
  5. Debug Triple services using grpc_cli

    main

    Since the Triple protocol is compatible with gRPC and enables gRPC reflection by default, you can use grpc_cli to debug services.

    1. List services: grpc_cli ls <address> -l
    2. Inspect request type: grpc_cli type <address> <message_type>
    3. Call a method: grpc_cli call <address> <method_name> "<json_payload>"
  6. Install compilation and formatting tools via dubbogo-cli

    main

    Run the following command to install essential development tools to your $GOPATH/bin:

    dubbogo-cli install all

    This installs:

    • protoc-gen-go-triple: For compiling Triple protocol interfaces.
    • imports-formatter: For organizing Go import blocks.
    dubbogo-cli install all
  7. Generate OpenAPI v3 documentation from Triple protobuf files

    main

    Use the protoc-gen-triple-openapi plugin to generate OpenAPI v3 documentation from .proto files that utilize the Triple protocol.

    After running the generation command, the plugin produces an OpenAPI documentation file (e.g., [filename].openapi.yaml).

    protoc --triple-openapi_out=. greet.proto
  8. Enable JSON Schema support for dubbo-go configuration in VS Code

    main

    To get autocompletion and validation for your dubbo-go configuration files in Visual Studio Code, you can associate your YAML configuration files with the official dubbo-go-schema.

    Add the following configuration to your VS Code settings.json file to enable schema support for dubbo.yaml, application.yaml, and dubbogo.yaml files.

    {
      "yaml.schemas": {
        "https://dubbogo.github.io/dubbo-go-schema/dubbo-go.json": [
          "dubbo.yaml",
          "application.yaml",
          "dubbogo.yaml"
        ]
      }
    }
  9. Use dubbogo-cli for application and demo creation

    main

    Use the following commands to scaffold new projects:

    • Create an application template: dubbogo-cli newApp . (creates a full project structure including api, build, chart, cmd, conf, and pkg/service).
    • Create an RPC demo: dubbogo-cli newDemo . (creates a minimal client/server RPC example in the current directory).
    dubbogo-cli newApp .
    dubbogo-cli newDemo .
  10. Install compilation and debugging tools

    main

    Install necessary tools for triple protocol compilation and code formatting to your $GOPATH/bin with a single command. This installs:

    • protoc-gen-go-triple: For triple protocol interface compilation.
    • imports-formatter: Used to tidy up code import blocks.
    dubbogo-cli install all