diff --git a/.gitignore b/.gitignore index 756cde067..6ee2153ca 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,7 @@ gradle-app.setting .project # JDT-specific (Eclipse Java Development Tools) -.classpath \ No newline at end of file +.classpath + +.idea +.DS_Store diff --git a/protos/src/main/protobuf/blockstream.proto b/protos/src/main/protobuf/blockstream.proto new file mode 100644 index 000000000..2c2164233 --- /dev/null +++ b/protos/src/main/protobuf/blockstream.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +option java_package = "com.hedera.block.protos"; +option java_outer_classname = "BlockStreamServiceGrpcProto"; + +service BlockStreamGrpc { + rpc GetBlock(BlockRequest) returns (Block) {} +} + +message Block { + int64 id = 1; + string value = 2; +} + +message BlockResponse { + int64 id = 1; +} + +message BlockRequest { + int64 id = 1; +} diff --git a/server/src/main/java/com/hedera/block/server/BlockStreamService.java b/server/src/main/java/com/hedera/block/server/BlockStreamService.java new file mode 100644 index 000000000..d4e5af7d7 --- /dev/null +++ b/server/src/main/java/com/hedera/block/server/BlockStreamService.java @@ -0,0 +1,37 @@ +package com.hedera.block.server; + +import com.google.protobuf.Descriptors; +import com.hedera.block.protos.BlockStreamServiceGrpcProto; +import io.grpc.stub.StreamObserver; +import io.helidon.webserver.grpc.GrpcService; + +import java.util.logging.Logger; + + +public class BlockStreamService implements GrpcService { + + private final Logger logger = Logger.getLogger(getClass().getName()); + + @Override + public Descriptors.FileDescriptor proto() { + return BlockStreamServiceGrpcProto.getDescriptor(); + } + + @Override + public String serviceName() { + return "BlockStreamGrpc"; + } + + @Override + public void update(Routing routing) { + routing.unary("GetBlock", this::getBlock); + } + + // @Override void invoke(ReqT request, StreamObserver responseObserver); + + private void getBlock(BlockStreamServiceGrpcProto.BlockRequest request, StreamObserver responseObserver) { + logger.info("GetBlock request received"); + } + + +} diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index c17a5cd15..0c45d077f 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -1,5 +1,6 @@ package com.hedera.block.server; +import com.hedera.block.protos.BlockStreamServiceGrpcProto; import com.hedera.block.protos.EchoServiceGrpcProto; import io.grpc.stub.StreamObserver; import io.helidon.webserver.WebServer; @@ -24,15 +25,23 @@ public static void main(String[] args) { .port(8080) .addRouting(HttpRouting.builder() .get("/greet", (req, res) -> res.send("Hello World!"))) +// .addRouting(GrpcRouting.builder() +// .service(new EchoService()) +// .unary(EchoServiceGrpcProto.getDescriptor(), +// "EchoService", +// "Echo", +// Server::grpcEcho)) .addRouting(GrpcRouting.builder() - .service(new EchoService()) - .unary(EchoServiceGrpcProto.getDescriptor(), - "EchoService", - "Echo", - Server::grpcEcho)) + .service(new BlockStreamService()) + .unary(BlockStreamServiceGrpcProto.getDescriptor(), + "BlockStreamGrpc", + "GetBlock", + Server::grpcGetBlock)) .build() .start(); } static void grpcEcho(EchoServiceGrpcProto.EchoRequest request, StreamObserver responseObserver) {} + + static void grpcGetBlock(BlockStreamServiceGrpcProto.BlockRequest request, StreamObserver responseObserver) {} }