How can I check the operation of the gRPC server? .. .. Introducing the grpcurl that I arrived at after researching various things. It seems that there are various functions, but only some of them will be introduced.
** Confirmed environment **
gRPC server configuration
Development environment
https://github.com/fullstorydev/grpcurl It is a tool that can realize the interaction with the gRPC server like a curl command. When you run the command, the gRPC server response will be returned in json format.
The details are written in the link, so I think you can just read it.
You need to install go.
** Download-Install ** https://golang.org/dl/ Please download the one that suits your environment from this site. For Windows, you can complete it without any problems by following the installer's instructions.
** Check settings ** For Windows, the following have been added to the environment variables:
** Installation confirmation **
Type go version at the command prompt, and if the version information is displayed, the installation is complete.
> go version
** Download-Install **
All you have to do is execute the following command.
> go get github.com/fullstorydev/grpcurl
> go install github.com/fullstorydev/grpcurl/cmd/grpcurl
The grpcurl command will be installed in the bin subfolder in the location specified in the $ GOPATH environment variable you checked earlier. By default,% GOPATH% bin is specified for Path, so you should be able to execute it immediately from the command prompt. If you cannot execute it, please check the Path specification.
** Installation confirmation **
If you can execute the following command, grpcurl installation is complete.
> grpcurl -help
Enable the reflection feature on your gRPC server.
If you are using grpc-spring-boot-starter, just add the following settings to application.yml.
application.yml
grpc:
enable-reflection: true
Note: Not supported by some versions of grpc-spring-boot-starter. (2.3.2 ~)
If you are not using starter, you can follow the steps below. (unconfirmed) https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md
Now you are ready to go.
// coming soon ...
Start the gRPC server to be checked for operation.
> grpcurl -plaintext localhost:6565 list
-plaintext You can check the operation in plain-text mode. If omitted, it can be confirmed by TLS.
localhost:6565 Specifies the host name and port number of the gRPC server.
When executed, the list of services on the server side will be displayed as shown below.
Execution result
> grpcurl -plaintext localhost:6565 list
helloworld.HelloWorldService
goodbyeworld.GoodByeWorldService
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
> grpcurl -plaintext localhost:6565 list helloworld.HelloWorldService
helloworld.HelloWorldService Specify the service name after the command to get the service list.
Execution result
> grpcurl -plaintext localhost:6565 list helloworld.HelloWorldService
Greeting
> grpcurl -plaintext localhost:6565 helloworld.HelloWorldService/Greeting
helloworld.HelloWorldService/Greeting Specify the service name / method name confirmed in the list.
When executed, the result will be displayed in json format.
Execution result
> grpcurl -plaintext localhost:6565 helloworld.HelloWorldService/Greeting
{
"message": "Hello World!"
}
> grpcurl -plaintext -d '{"lang":"Java"}' localhost:6565 helloworld.HelloWorldService/Greeting
You can write the parameters in json format after -d. It was written on the site, but it didn't work because the single quotes got angry: cold_sweat :. Therefore. .. ..
> grpcurl -plaintext -d @ localhost:6565 helloworld.HelloWorldService/Greeting
I tried this because the method that you can enter the parameter with STDIN by specifying'@' after -d was introduced.
> grpcurl -plaintext -d @ localhost:6565 helloworld.HelloWorldService/Greeting
{
"lang": "Java"
}
EOM
EOM
You can enter with Ctrl + Z on Windows and Ctrl + D on Unix.
It is displayed as ^ Z
at the Windows command prompt.
When I ran it, the result was excellent. : relaxed:
Execution result
> grpcurl -plaintext -d @ localhost:6565 helloworld.HelloWorldService/Greeting
{
"lang": "Java"
}
^Z
{
"message": "Hello Java World!"
}
If you want to output the result to a file, it looks like this.
grpcurl -plaintext localhost:6565 helloworld.HelloWorldService/Greeting > GreetingResult.json
GreetingResult.json
{
"message": "Hello World!"
}
end
Recommended Posts