Использование стартового приложения Springboot. Все работает. Затем я переместил клиент и сервер на новые пакеты. Все компилируется, но во время выполнения, когда я запускаю клиент, я получаю ошибку: UNIMPLEMENTED Method not found.
Я проверил, что метод действительно реализован. Когда я запускаю приложение Springboot, где я подтверждаю, что бин был загружен? Я просто вижу подтверждение того, что приложение запущено и работает, но в журнале нет списка загруженных компонентов.
Вот мое приложение Springboot. Все, что я сделал, это переместил bean-компонент клиента и сервера в новый пакет с именами example.client и example.server. прежде чем они были в той же упаковке, что и весенняя загрузка com.test.MyApplication
io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found: example.GreetingService/greetingWithResponseStream
at io.grpc.Status.asRuntimeException(Status.java:526)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:434)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
GreetingService.proto:
syntax = "proto3";
package example;
message HelloRequest {
string name = 1;
}
message HelloResponse {
string greeting = 1;
}
service GreetingService {
rpc greeting (HelloRequest) returns (HelloResponse);
rpc greetingWithResponseStream (HelloRequest) returns (stream HelloResponse);
rpc greetingWithRequestStream (stream HelloRequest) returns (HelloResponse);
rpc greetingWithRequestResponseStream (stream HelloRequest) returns (stream HelloResponse);
}
import example.GreetingServiceOuterClass;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.List;
@GrpcService
public class GreetingServiceImpl extends GreetingServiceGrpc.GreetingServiceImplBase{
@Override
public void greeting(GreetingServiceOuterClass.HelloRequest request, StreamObserver<GreetingServiceOuterClass.HelloResponse> responseObserver) {
GreetingServiceOuterClass.HelloResponse response = GreetingServiceOuterClass.HelloResponse.newBuilder()
.setGreeting("HELLO, THERE, " + request.getName())
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
@Override
public void greetingWithResponseStream(GreetingServiceOuterClass.HelloRequest request, StreamObserver<GreetingServiceOuterClass.HelloResponse> responseObserver) {
GreetingServiceOuterClass.HelloResponse response = GreetingServiceOuterClass.HelloResponse.newBuilder()
.setGreeting("(Stream Response) Hello there, " + request.getName())
.build();
responseObserver.onNext(response);
responseObserver.onNext(response);
responseObserver.onNext(response);
responseObserver.onCompleted();
}
@Override
public StreamObserver<GreetingServiceOuterClass.HelloRequest> greetingWithRequestStream(StreamObserver<GreetingServiceOuterClass.HelloResponse> responseObserver) {
return new StreamObserver<GreetingServiceOuterClass.HelloRequest>() {
private List<String> nameList = new ArrayList<>();
@Override
public void onNext(GreetingServiceOuterClass.HelloRequest request) {
nameList.add(request.getName());
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
@Override
public void onCompleted() {
GreetingServiceOuterClass.HelloResponse response = GreetingServiceOuterClass.HelloResponse.newBuilder()
.setGreeting("(Stream Request) Hello there, " + String.join(" ", nameList))
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
}
@Override
public StreamObserver<GreetingServiceOuterClass.HelloRequest> greetingWithRequestResponseStream(StreamObserver<GreetingServiceOuterClass.HelloResponse> responseObserver) {
return new StreamObserver<GreetingServiceOuterClass.HelloRequest>() {
private List<String> nameList = new ArrayList<>();
@Override
public void onNext(GreetingServiceOuterClass.HelloRequest request) {
nameList.add(request.getName());
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
@Override
public void onCompleted() {
nameList.stream()
.map(name -> GreetingServiceOuterClass.HelloResponse.newBuilder().setGreeting("(Stream Request/Response) Hello there, " + name).build())
.forEach(responseObserver::onNext);
responseObserver.onCompleted();
}
};
}
}
package example.client;
import example.GreetingServiceGrpc;
import example.GreetingServiceOuterClass;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
import java.util.stream.Stream;
public class Client {
public static void main(String[] args) {
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:8081")
.usePlaintext()
.build();
GreetingServiceGrpc.GreetingServiceBlockingStub stub = GreetingServiceGrpc.newBlockingStub(channel);
GreetingServiceOuterClass.HelloRequest request = GreetingServiceOuterClass.HelloRequest.newBuilder().setName("Steve").build();
GreetingServiceOuterClass.HelloResponse response = stub.greeting(request);
System.out.println(response);
}
public static class RequestStreamClient {
public static void main(String[] args) throws InterruptedException {
new Thread(() -> {
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:8081")
.usePlaintext()
.build();
GreetingServiceGrpc.GreetingServiceStub stub = GreetingServiceGrpc.newStub(channel);
StreamObserver<GreetingServiceOuterClass.HelloRequest> requestStream =
stub.greetingWithRequestStream(new StreamObserver<GreetingServiceOuterClass.HelloResponse>() {
@Override
public void onNext(GreetingServiceOuterClass.HelloResponse response) {
System.out.println(response);
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
@Override
public void onCompleted() {
}
});
Stream.of("Steve1", "Steve2", "Steve3")
.map(name -> GreetingServiceOuterClass.HelloRequest.newBuilder().setName(name).build())
.forEach(requestStream::onNext);
requestStream.onCompleted();
}).start();
Thread.sleep(10000);
}
}
}