I tried to check the operation of gRPC server with grpcurl

Introduction

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

What is grpcurl

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.

Preparation (Windows edition)

1. 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

2. Install grpcurl

** 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 

3. Reflection settings

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.

TODO preparation (Mac edition)

// coming soon ...

Try using

Start the gRPC server to be checked for operation.

Display service list

> 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

Display method list

> 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

Service call

> 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!"
}

Service call (with request parameter)

> 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!"
}

bonus

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

I tried to check the operation of gRPC server with grpcurl
I tried to check the operation of http request (Put) with Talented API Tester
I tried to build the environment of PlantUML Server with Docker
I tried to summarize the key points of gRPC design and development
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried to measure and compare the speed of GraalVM with JMH
I tried using the Server Push function of Servlet 4.0
I tried to summarize the state transition of docker
I tried to compare the infrastructure technology of engineers these days with cooking.
I tried to reduce the capacity of Spring Boot
[Beginner's point of view] I tried to solve the FizzBuzz problem "easily" with Ruby!
I tried to investigate the mechanism of Emscripten by using it with the Sudoku solver
I tried to increase the processing speed with spiritual engineering
I tried to summarize the basics of kotlin and java
[Swift] I tried to implement the function of the vending machine
Check the operation of two roles with a chat application
I tried to summarize the basic grammar of Ruby briefly
I tried to link chat with Minecraft server with Discord API
I tried to build the environment of WSL2 + Docker + VSCode
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried to interact with Java
I tried to explain the method
I tried to implement the image preview function with Rails / jQuery
I tried to summarize the methods of Java String and StringBuilder
I tried to solve the problem of Google Tech Dev Guide
I tried to summarize the methods used
Check the contents of params with pry
I tried to get started with WebAssembly
I tried to express the result of before and after of Date class with a number line
I tried to implement the Iterator pattern
I tried to take a look at the flow of Android development environment construction with Android Studio
I tried to summarize the Stream API
I tried to implement ModanShogi with Kinx
Check the operation of the interface through threads
[Ruby] I tried to diet the if statement code with the ternary operator
I examined the flow of TCP communication with Spring Integration (server edition)
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to make full use of the CPU core in Ruby
After all I wanted to preview the contents of mysql with Docker ...
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
I want to output the day of the week
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to manage login information with JMX
I tried to organize the session in Rails
I tried to chew C # (basic of encapsulation)
I want to var_dump the contents of the intent
I tried to set tomcat to run the Servlet.
I tried to implement a server using Netty
I tried using the profiler of IntelliJ IDEA
I tried to break a block with java (1)
I checked the number of taxis with Ruby
I tried to get the distance from the address string to the nearest station with ruby
Rails6 I want to make an array of values with a check box
I tried to clone a web application full of bugs with Spring Boot
[Beginner] I tried to decorate the bar after displaying the details of the hamburger menu
I wanted to start the AP server and debug with just the Maven command
I tried what I wanted to try with Stream softly.
I tried to summarize the points to consider when acquiring location information with the iOS application ③
I tried to implement file upload with Spring MVC