Неопределенная ошибка на примере Vert.x gRP C - PullRequest
0 голосов
/ 09 марта 2020

В настоящее время я изучаю gRPC в Vert.x и пытаюсь запустить пример gRPC на Vert.x сайте https://vertx.io/docs/vertx-grpc/java (пример helloworld). Все выглядит хорошо, но когда я запускаю клиент, появляется это исключение:

io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method helloworld.Greeter/SayHello is unimplemented

И это странно, потому что я реализовал метод sayHello в своем приложении. Вот мой код в client классе:

ublic class Client extends AbstractVerticle {
public static void main(String[] args) {
    Runner.runExample(Client.class);
}

@Override
public void start() throws Exception {
    ManagedChannel channel = VertxChannelBuilder
            .forAddress(vertx, "localhost", 8080)
            .usePlaintext(true)
            .build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
    stub.sayHello(request, asyncResponse -> {
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
}

}

А вот мой server класс:

public class Server extends AbstractVerticle {
public static void main(String[] args) {
    Runner.runExample(Server.class);
}

@Override
public void start() throws Exception {
    VertxServer server = VertxServerBuilder
            .forAddress(vertx, "localhost", 8080)
            .addService(new GreeterGrpc.GreeterVertxImplBase() {

        @Override
        public void sayHello(HelloRequest request, Promise<HelloReply> future) {
System.out.println("Hello " + request.getName());
                    future.complete(HelloReply.newBuilder().setMessage(request.getName()).build());
        }
    }).build();
    server.start(ar -> {
        if (ar.succeeded()) {
            System.out.println("gRPC service started");
        } else {
            System.out.println("Could not start server " + ar.cause().getMessage());
        }
    });
}

} ​​

Остальная часть кода была сгенерирована этим helloworld.proto:

    syntax = "proto3";
option java_multiple_files = true;
option java_package = "examples";
option java_outer_classname = "HelloWorldProto";
package helloworld;

// The greeting service definition.
service Greeter {
    // Sends a greeting
    rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
    string name = 1;
}

// The response message containing the greetings
message HelloReply {
    string message = 1;
}
...