@Override public void start() throws Exception { // The rcp service EmptyPingPongServiceGrpc.EmptyPingPongServiceVertxImplBase service = new EmptyPingPongServiceGrpc.EmptyPingPongServiceVertxImplBase() { @Override public void emptyCall(EmptyProtos.Empty request, Future<EmptyProtos.Empty> future) { future.complete(EmptyProtos.Empty.newBuilder().build()); } }; // Create the server VertxServer rpcServer = VertxServerBuilder .forPort(vertx, 8080) .addService(service) .build(); // start the server rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } }); } }
@java.lang.Override @java.lang.SuppressWarnings("unchecked") public io.grpc.stub.StreamObserver<Req> invoke( io.grpc.stub.StreamObserver<Resp> responseObserver) { switch (methodId) { case METHODID_FULL_DUPLEX_CALL: io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingOutputCallRequest> request0 = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingOutputCallRequest>create(); serviceImpl.fullDuplexCall( io.vertx.grpc.GrpcBidiExchange.<io.vertx.example.grpc.Messages.StreamingOutputCallRequest, io.vertx.example.grpc.Messages.StreamingOutputCallResponse>create( request0, (io.grpc.stub.StreamObserver<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>) responseObserver)); return (io.grpc.stub.StreamObserver<Req>) request0.readObserver(); default: throw new AssertionError(); } } }
@Override public void start() throws Exception { VertxServer server = VertxServerBuilder.forAddress(vertx, "localhost", 8080).addService(new GreeterGrpc.GreeterVertxImplBase() { @Override public void sayHello(HelloRequest request, Future<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()); } }); } }
/** * <pre> * A client-to-server streaming RPC. * Accepts a stream of Points on a route being traversed, returning a * RouteSummary when traversal is completed. * </pre> */ public void recordRoute(io.vertx.core.Handler< io.vertx.grpc.GrpcUniExchange<io.grpc.examples.routeguide.Point, io.grpc.examples.routeguide.RouteSummary>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.RouteSummary> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.examples.routeguide.RouteSummary>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getRecordRouteMethod(), getCallOptions()), readStream.readObserver()))); }
@Override public void recordRoute(GrpcReadStream<Point> request, Future<RouteSummary> response) { request.exceptionHandler(err -> { System.out.println("recordRoute cancelled"); }); RouteRecorder recorder = new RouteRecorder(); request.handler(recorder::append); request.endHandler(v -> { response.complete(recorder.build()); }); }
/** * <pre> * A sequence of requests with each request served by the server immediately. * As one request could lead to multiple responses, this interface * demonstrates the idea of full duplexing. * </pre> */ public void fullDuplexCall( io.vertx.grpc.GrpcBidiExchange<io.vertx.example.grpc.Messages.StreamingOutputCallRequest, io.vertx.example.grpc.Messages.StreamingOutputCallResponse> exchange) { exchange.setReadObserver(asyncUnimplementedStreamingCall(getFullDuplexCallMethod(), exchange.writeObserver())); }
@Override public void fullDuplexCall(GrpcBidiExchange<Messages.StreamingOutputCallRequest, Messages.StreamingOutputCallResponse> exchange) { exchange .handler(req -> { System.out.println("Server: received request"); vertx.setTimer(500L, t -> { exchange.write(Messages.StreamingOutputCallResponse.newBuilder().build()); }); }); } };
/** * <pre> * A server-to-client streaming RPC. * Obtains the Features available within the given Rectangle. Results are * streamed rather than returned at once (e.g. in a response message with a * repeated field), as the rectangle may cover a large area and contain a * huge number of features. * </pre> */ public void listFeatures(io.grpc.examples.routeguide.Rectangle request, io.vertx.grpc.GrpcWriteStream<io.grpc.examples.routeguide.Feature> response) { asyncUnimplementedUnaryCall(getListFeaturesMethod(), response.writeObserver()); }
/** * <pre> * A client-to-server streaming RPC. * Accepts a stream of Points on a route being traversed, returning a * RouteSummary when traversal is completed. * </pre> */ public void recordRoute(io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.Point> request, io.vertx.core.Future<io.grpc.examples.routeguide.RouteSummary> response) { request.setReadObserver(asyncUnimplementedStreamingCall(getRecordRouteMethod(), RouteGuideGrpc.toObserver(response.completer()))); }
@java.lang.Override @java.lang.SuppressWarnings("unchecked") public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) { switch (methodId) { case METHODID_STREAMING_OUTPUT_CALL: serviceImpl.streamingOutputCall((io.vertx.example.grpc.Messages.StreamingOutputCallRequest) request, (io.vertx.grpc.GrpcWriteStream<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>) io.vertx.grpc.GrpcWriteStream.create(responseObserver)); break; default: throw new AssertionError(); } }
@Override public void start() throws Exception { // The rcp service PingPongServiceGrpc.PingPongServiceVertxImplBase service = new PingPongServiceGrpc.PingPongServiceVertxImplBase() { @Override public void unaryCall(Messages.SimpleRequest request, Future<Messages.SimpleResponse> future) { future.complete(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build()); } }; // Create the server VertxServer rpcServer = VertxServerBuilder .forPort(vertx, 8080) .addService(service) .build(); // start the server rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } }); } }
/** * <pre> * A Bidirectional streaming RPC. * Accepts a stream of RouteNotes sent while a route is being traversed, * while receiving other RouteNotes (e.g. from other users). * </pre> */ public void routeChat(io.vertx.core.Handler< io.vertx.grpc.GrpcBidiExchange<io.grpc.examples.routeguide.RouteNote, io.grpc.examples.routeguide.RouteNote>> handler) { final io.vertx.grpc.GrpcReadStream<io.grpc.examples.routeguide.RouteNote> readStream = io.vertx.grpc.GrpcReadStream.<io.grpc.examples.routeguide.RouteNote>create(); handler.handle(io.vertx.grpc.GrpcBidiExchange.create(readStream, asyncBidiStreamingCall( getChannel().newCall(getRouteChatMethod(), getCallOptions()), readStream.readObserver()))); } }
/** * <pre> * A sequence of requests followed by one response (streamed upload). * The server returns the aggregated size of client payload as the result. * </pre> */ public void streamingInputCall(io.vertx.core.Handler< io.vertx.grpc.GrpcUniExchange<io.vertx.example.grpc.Messages.StreamingInputCallRequest, io.vertx.example.grpc.Messages.StreamingInputCallResponse>> handler) { final io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingInputCallResponse> readStream = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingInputCallResponse>create(); handler.handle(io.vertx.grpc.GrpcUniExchange.create(readStream, asyncClientStreamingCall( getChannel().newCall(getStreamingInputCallMethod(), getCallOptions()), readStream.readObserver()))); } }
/** * <pre> * A Bidirectional streaming RPC. * Accepts a stream of RouteNotes sent while a route is being traversed, * while receiving other RouteNotes (e.g. from other users). * </pre> */ public void routeChat( io.vertx.grpc.GrpcBidiExchange<io.grpc.examples.routeguide.RouteNote, io.grpc.examples.routeguide.RouteNote> exchange) { exchange.setReadObserver(asyncUnimplementedStreamingCall(getRouteChatMethod(), exchange.writeObserver())); }
/** * <pre> * One request followed by a sequence of responses (streamed download). * The server returns the payload with client desired type and sizes. * </pre> */ public void streamingOutputCall(io.vertx.example.grpc.Messages.StreamingOutputCallRequest request, io.vertx.grpc.GrpcWriteStream<io.vertx.example.grpc.Messages.StreamingOutputCallResponse> response) { asyncUnimplementedUnaryCall(getStreamingOutputCallMethod(), response.writeObserver()); }
/** * <pre> * A sequence of requests followed by one response (streamed upload). * The server returns the aggregated size of client payload as the result. * </pre> */ public void streamingInputCall(io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingInputCallRequest> request, io.vertx.core.Future<io.vertx.example.grpc.Messages.StreamingInputCallResponse> response) { request.setReadObserver(asyncUnimplementedStreamingCall(getStreamingInputCallMethod(), ProducerServiceGrpc.toObserver(response.completer()))); }
@Override public void start() throws Exception { // The rcp service ProducerServiceGrpc.ProducerServiceVertxImplBase service = new ProducerServiceGrpc.ProducerServiceVertxImplBase() { @Override public void streamingInputCall(GrpcReadStream<Messages.StreamingInputCallRequest> request, Future<Messages.StreamingInputCallResponse> future) { request.handler(payload -> { System.out.println(payload.getPayload().getType().getNumber()); }).endHandler(v -> { System.out.println("Request has ended."); future.complete(Messages.StreamingInputCallResponse.newBuilder().build()); }); } }; // Create the server VertxServer rpcServer = VertxServerBuilder .forPort(vertx, 8080) .addService(service) .build(); // start the server rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } }); } }
/** * <pre> * A sequence of requests with each request served by the server immediately. * As one request could lead to multiple responses, this interface * demonstrates the idea of full duplexing. * </pre> */ public void fullDuplexCall(io.vertx.core.Handler< io.vertx.grpc.GrpcBidiExchange<io.vertx.example.grpc.Messages.StreamingOutputCallResponse, io.vertx.example.grpc.Messages.StreamingOutputCallRequest>> handler) { final io.vertx.grpc.GrpcReadStream<io.vertx.example.grpc.Messages.StreamingOutputCallResponse> readStream = io.vertx.grpc.GrpcReadStream.<io.vertx.example.grpc.Messages.StreamingOutputCallResponse>create(); handler.handle(io.vertx.grpc.GrpcBidiExchange.create(readStream, asyncBidiStreamingCall( getChannel().newCall(getFullDuplexCallMethod(), getCallOptions()), readStream.readObserver()))); } }
.forPort(vertx, 8080) .addService(service) .build(); rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace();
.forPort(vertx, 8080) .addService(service) .build(); rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace();