Using gRPC CLI

此页面解释了如何使用 gRPC CLI(一个类似 grpcurl 的工具)。 首先查看基本的 Quarkus CLI 使用方法:

Table of Contents

Examples

显示 gRPC CLI 帮助:

quarkus grpc -h
Usage: grpc [-h] [COMMAND]
  -h, --help   Display this help message.
Commands:
  list      grpc list
  describe  grpc describe
  invoke    grpc invoke

列出所有可用的 gRPC 服务:

quarkus grpc list localhost:8080

helloworld.Greeter
grpc.health.v1.Health

描述一个服务:

quarkus grpc describe localhost:8080 helloworld.Greeter

{
  "name": "helloworld.proto",
  "package": "helloworld",
  "dependency": ["google/protobuf/empty.proto"],
  "messageType": [{
    "name": "HelloRequest",
    "field": [{
      "name": "name",
      "number": 1,
      "label": "LABEL_OPTIONAL",
      "type": "TYPE_STRING"
    }]
  }, {
    "name": "HelloReply",
    "field": [{
      "name": "message",
      "number": 1,
      "label": "LABEL_OPTIONAL",
      "type": "TYPE_STRING"
    }]
  }],
  "service": [{
    "name": "Greeter",
    "method": [{
      "name": "SayHello",
      "inputType": ".helloworld.HelloRequest",
      "outputType": ".helloworld.HelloReply",
      "options": {
      }
    }, {
      "name": "SayJo",
      "inputType": ".google.protobuf.Empty",
      "outputType": ".helloworld.HelloReply",
      "options": {
      }
    }, {
      "name": "ThreadName",
      "inputType": ".helloworld.HelloRequest",
      "outputType": ".helloworld.HelloReply",
      "options": {
      }
    }]
  }],
  "options": {
    "javaPackage": "examples",
    "javaOuterClassname": "HelloWorldProto",
    "javaMultipleFiles": true,
    "objcClassPrefix": "HLW"
  },
  "syntax": "proto3"
}
{
  "name": "google/protobuf/empty.proto",
  "package": "google.protobuf",
  "messageType": [{
    "name": "Empty"
  }],
  "options": {
    "javaPackage": "com.google.protobuf",
    "javaOuterClassname": "EmptyProto",
    "javaMultipleFiles": true,
    "goPackage": "google.golang.org/protobuf/types/known/emptypb",
    "ccEnableArenas": true,
    "objcClassPrefix": "GPB",
    "csharpNamespace": "Google.Protobuf.WellKnownTypes"
  },
  "syntax": "proto3"
}

调用一个服务方法:

quarkus grpc invoke localhost:8080 helloworld.Greeter/SayHello -d '{"name" : "gRPC"}'

{
  "message": "Hello gRPC"
}