Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial gRPC CLI #41249

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,16 @@
<artifactId>quarkus-grpc-stubs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-reflection</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-deployment</artifactId>
Expand Down
129 changes: 129 additions & 0 deletions docs/src/main/asciidoc/grpc-cli.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc
////
= Using gRPC CLI

Check warning on line 6 in docs/src/main/asciidoc/grpc-cli.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in 'Using gRPC CLI'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in 'Using gRPC CLI'.", "location": {"path": "docs/src/main/asciidoc/grpc-cli.adoc", "range": {"start": {"line": 6, "column": 3}}}, "severity": "INFO"}
include::_attributes.adoc[]
:categories: serialization
:summary: This page explains how to use gRPC CLI.
:topics: grpc,cli
:extensions: io.quarkus:quarkus-grpc-cli

This page explains how to use gRPC CLI -- a grpcurl-like tool.

See basic Quarkus CLI usage first:

* xref:cli-tooling.adoc[CLI tooling]

== Examples

Display gRPC CLI help:

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

List all available gRPC services:

[source,shell]
----
quarkus grpc list localhost:8080

helloworld.Greeter
grpc.health.v1.Health
----

Describe a service:

[source,shell]
----
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"
}
----

Invoke a service method:

[source,shell]
----
quarkus grpc invoke localhost:8080 helloworld.Greeter/SayHello -d '{"name" : "gRPC"}'

{
"message": "Hello gRPC"
}
----
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/grpc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ Quarkus gRPC is based on https://vertx.io/docs/vertx-grpc/java/[Vert.x gRPC].
* xref:grpc-xds.adoc[Enabling xDS gRPC support]
* xref:grpc-generation-reference.adoc[gRPC code generation reference guide]
* xref:grpc-reference.adoc[gRPC reference guide]
* xref:grpc-cli.adoc[gRPC CLI support]
7 changes: 4 additions & 3 deletions extensions/grpc/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
<name>Quarkus - gRPC - API</name>

<dependencies>
<!-- Do not depend on the ArC extension here as we are not in an extension -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand All @@ -39,4 +40,4 @@
</dependency>
</dependencies>

</project>
</project>
90 changes: 90 additions & 0 deletions extensions/grpc/cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>quarkus-grpc-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-grpc-cli</artifactId>
<name>Quarkus - gRPC - CLI</name>
<description>gRPC CLI</description>

<properties>
<main.class>io.quarkus.grpc.cli.GrpcCommand</main.class>
</properties>

<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-grpc-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-reflection</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>

<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>

<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>

</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.quarkus.grpc.cli;

import java.util.List;

import com.google.protobuf.ByteString;
import com.google.protobuf.DescriptorProtos;
import com.google.protobuf.util.JsonFormat;

import io.grpc.reflection.v1.MutinyServerReflectionGrpc;
import io.grpc.reflection.v1.ServerReflectionRequest;
import io.grpc.reflection.v1.ServerReflectionResponse;
import io.smallrye.mutiny.Multi;
import picocli.CommandLine;

@CommandLine.Command(name = "describe", sortOptions = false, header = "gRPC describe")
public class DescribeCommand extends GcurlBaseCommand {

public String getAction() {
return "describe";
}

@Override
protected void execute(MutinyServerReflectionGrpc.MutinyServerReflectionStub stub) {
ServerReflectionRequest request = ServerReflectionRequest
.newBuilder()
.setFileContainingSymbol(unmatched.get(1))
.build();
Multi<ServerReflectionResponse> response = stub.serverReflectionInfo(Multi.createFrom().item(request));
response.toUni().map(r -> {
List<ByteString> list = r.getFileDescriptorResponse().getFileDescriptorProtoList();
for (ByteString bs : list) {
try {
DescriptorProtos.FileDescriptorProto fdp = DescriptorProtos.FileDescriptorProto.parseFrom(bs);
log(JsonFormat.printer().print(fdp));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return null;
}).await().indefinitely();
}
}
Loading
Loading