Skip to content

Bangseungjae/grpc-study

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gPRC-STUDY

gRPC Study

I config gradle and maven setting


How Hander *.proto?

  1. add default setting like
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.bsj.models";

message Die {
  int32 value = 1;
}

message Player {
  string name = 1;
  int32 position = 2;
}

message GameState {
  repeated Player player = 1;
}

service GameService {
  rpc roll(stream Die) returns (stream GameState);
}

  1. Generate Proto
./gradlew clean
./gradlew generateProto


  1. You can Check generated File

image


  1. Implementation proto file like
public class GameService extends GameServiceGrpc.GameServiceImplBase {

    @Override
    public StreamObserver<Die> roll(StreamObserver<GameState> responseObserver) {
        Player client = Player.newBuilder()
                .setName("client")
                .setPosition(0)
                .build();

        Player server = Player.newBuilder()
                .setName("server")
                .setPosition(0)
                .build();

        return new DieStreamingRequest(client, server, responseObserver);
    }
}
  1. Start Server

public class GrpcServer {

    public static void main(String[] args) throws IOException, InterruptedException {
        Server server = ServerBuilder.forPort(6565)
                .addService(new GameService())
                .build();

        server.start();

        server.awaitTermination();
    }
}

Releases

No releases published

Packages

No packages published

Languages