Introduction to Grpc NetWorkFilter

Introduction to Grpc NetWorkFilter

Using grpc to Call Service Providers

The following documentation conforms to the code

Define Pixiu Configuration File

static_resources:
  listeners:
    - name: "net/http"
      protocol_type: "HTTP"
      address:
        socket_address:
          address: "0.0.0.0"
          port: 8881
      filter_chains:
        filters:
          - name: dgp.filter.httpconnectionmanager
            config:
              route_config:
                routes:
                  - match:
                      prefix: "/api/v1"
                    route:
                      cluster: "test-grpc"
                      cluster_not_found_response_code: 505
              http_filters:
                - name: dgp.filter.http.grpcproxy
                  config:
                    path: /mnt/d/WorkSpace/GoLandProjects/dubbo-go-pixiu/samples/http/grpc/proto
                - name: dgp.filter.http.response
                  config:
              server_name: "test-http-grpc"
              generate_request_id: false
      config:
        idle_timeout: 5s
        read_timeout: 5s
        write_timeout: 5s
  clusters:
    - name: "test-grpc"
      lb_policy: "RoundRobin"
      endpoints:
        - socket_address:
            address: 127.0.0.1
            port: 50001
            protocol_type: "GRPC"
  timeout_config:
    connect_timeout: "5s"
    request_timeout: "10s"
  shutdown_config:
    timeout: "60s"
    step_timeout: "10s"
    reject_policy: "immediacy"

The Grpc server is defined in the “cluster”

Currently, HTTP requests only support JSON body parsing parameters.

Prepare the Server

generate pb files under with command:

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative hello_grpc.proto

Start the Server

Run

go run server.go

Start Pixiu

./dubbo-go-pixiu gateway start --config {CURRENT_PATH}/samples/http/grpc/pixiu/conf.yaml

Test Using Curl

Run the curl command with the following:

curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser
curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser -X POST -d '{"userId":1}'

If the response body is JSON, the Content-Type header will be set to application/json. If it is just plain text, the Content-Type header is text/plain.

Last modified September 30, 2024: Translate (7498923da5)