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

  1. static_resources:
  2. listeners:
  3. - name: "net/http"
  4. protocol_type: "HTTP"
  5. address:
  6. socket_address:
  7. address: "0.0.0.0"
  8. port: 8881
  9. filter_chains:
  10. filters:
  11. - name: dgp.filter.httpconnectionmanager
  12. config:
  13. route_config:
  14. routes:
  15. - match:
  16. prefix: "/api/v1"
  17. route:
  18. cluster: "test-grpc"
  19. cluster_not_found_response_code: 505
  20. http_filters:
  21. - name: dgp.filter.http.grpcproxy
  22. config:
  23. path: /mnt/d/WorkSpace/GoLandProjects/dubbo-go-pixiu/samples/http/grpc/proto
  24. - name: dgp.filter.http.response
  25. config:
  26. server_name: "test-http-grpc"
  27. generate_request_id: false
  28. config:
  29. idle_timeout: 5s
  30. read_timeout: 5s
  31. write_timeout: 5s
  32. clusters:
  33. - name: "test-grpc"
  34. lb_policy: "RoundRobin"
  35. endpoints:
  36. - socket_address:
  37. address: 127.0.0.1
  38. port: 50001
  39. protocol_type: "GRPC"
  40. timeout_config:
  41. connect_timeout: "5s"
  42. request_timeout: "10s"
  43. shutdown_config:
  44. timeout: "60s"
  45. step_timeout: "10s"
  46. 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:

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

Start the Server

Run

  1. go run server.go

Start Pixiu

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

Test Using Curl

Run the curl command with the following:

  1. curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser
  1. 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.

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)