Search in sources :

Example 1 with HelloResponse

use of org.baeldung.grpc.HelloResponse in project tutorials by eugenp.

the class GrpcClient method main.

public static void main(String[] args) throws InterruptedException {
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080).usePlaintext(true).build();
    HelloServiceGrpc.HelloServiceBlockingStub stub = HelloServiceGrpc.newBlockingStub(channel);
    HelloResponse helloResponse = stub.hello(HelloRequest.newBuilder().setFirstName("Baeldung").setLastName("gRPC").build());
    System.out.println("Response received from server:\n" + helloResponse);
    channel.shutdown();
}
Also used : HelloResponse(org.baeldung.grpc.HelloResponse) ManagedChannel(io.grpc.ManagedChannel) HelloServiceGrpc(org.baeldung.grpc.HelloServiceGrpc)

Example 2 with HelloResponse

use of org.baeldung.grpc.HelloResponse in project tutorials by eugenp.

the class HelloServiceImpl method hello.

@Override
public void hello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
    System.out.println("Request received from client:\n" + request);
    String greeting = new StringBuilder().append("Hello, ").append(request.getFirstName()).append(" ").append(request.getLastName()).toString();
    HelloResponse response = HelloResponse.newBuilder().setGreeting(greeting).build();
    responseObserver.onNext(response);
    responseObserver.onCompleted();
}
Also used : HelloResponse(org.baeldung.grpc.HelloResponse)

Aggregations

HelloResponse (org.baeldung.grpc.HelloResponse)2 ManagedChannel (io.grpc.ManagedChannel)1 HelloServiceGrpc (org.baeldung.grpc.HelloServiceGrpc)1