Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gRPC not generating interface for a service, only a service class

I am new to gRPC and have this problem: I created a .proto with rpc service definition. After compilation I get generated sources: all messages have a class that implements an interface. However a service itself doesn't implement any interface - it's simply not generated. And that's the interface I'm supposed to implement in my server. What am I doing wrong? I am pretty sure gRPC documentation says nothing about this problem.

My .proto service:

syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.blah.my.rpc.api";
option java_outer_classname = "MyServiceProto";
option objc_class_prefix = "Pb";

package com.blah.my.rpc.api;

service MyService
{
  rpc connect(PbEmptyMessage) returns (PbParameterGroup){}

  rpc getParams(PbGenList) returns (PbParameterGroup){}

}

message PbEmptyMessage
{
}

message PbGenId
{
      string paramName = 1;
      string systemName = 2;
      string sName = 3;
      string sId = 4;
}

message PbParameterGroup
{
       bytes sParameters = 2;
       fixed64 time  = 3;
}

My plugin definition in maven:

<extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.4.0.Final</version>
            </extension>
        </extensions>

        <plugins>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.5.0</version>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}
                    </protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:0.14.0:exe:${os.detected.classifier}</pluginArtifact>
                    <protoSourceRoot>${basedir}/src/main/resources</protoSourceRoot>
                    <outputDirectory>${basedir}/target/generated-sources</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
like image 274
Iwavenice Avatar asked May 22 '16 11:05

Iwavenice


People also ask

Can a gRPC server have multiple services?

All the gRPC implementations support multiple services in the same process and port.

Is gRPC stateless or stateful?

At the moment, gRPC server methods are involved in a completely stateless way, making it not possible to implement a reliable stateful protocol.

What is blocking stub in gRPC?

a blocking/synchronous stub: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception. a non-blocking/asynchronous stub that makes non-blocking calls to the server, where the response is returned asynchronously.

Does gRPC require Protobuf?

Protobuf is the most commonly used IDL (Interface Definition Language) for gRPC. It's where you basically store your data and function contracts in the form of a proto file. As this is in the form of a contract, both the client and server need to have the same proto file.


1 Answers

Got the answer from plugin developer.

1st thing: goals should be:

<goal>compile</goal>
<goal>compile-custom</goal>

2d and main thing: <outputDirectory> is reused between the two goals and thus its contents are rewritten. Removing this parameter solved the problem.

like image 165
Iwavenice Avatar answered Oct 06 '22 00:10

Iwavenice