Creating .proto File for Messages and Services
Create the .proto file for the FTP service project.
As discussed previously, in gRPC, the .proto
files are used to define the structure of the services and messages exchanged between clients and servers. After defining the .proto
file, we will generate Java code from it in order to implement gRPC clients and servers in Java.
FTP service .proto
file
In the ftp-service-proto
project created in the Configuring Protobuf in Java lesson, we will create a .proto
file for the FTP service. First, we need to create a directory named proto
in src/main
. This is the source root path for the .proto
file specified in the <configuration>
section of the protobuf-maven-plugin
. (Since this project will only contain the proto file, we can delete the java
directory from src/main
.)
Inside the proto
directory, create a file named ftp_service.proto
. In this file, we will specify the RPCs that our FTP service will expose, along with the request and response messages.
You can also use plugins for editor support in creating .proto
files. IntelliJ IDEA users can install the Protocol Buffers plugin. Eclipse users can also find similar tools designed for ease in creating .proto
files. ...