@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()); } }); } }
@Override public VertxServer shutdown() { return shutdown(ar -> {}); }
@Test public void testBilto(TestContext ctx) throws Exception { Async started = ctx.async(); List<GrpcVerticle> verticles = Collections.synchronizedList(new ArrayList<>()); vertx.deployVerticle(() -> { GrpcVerticle verticle = new GrpcVerticle(0); verticles.add(verticle); return verticle; }, new DeploymentOptions().setInstances(2), ctx.asyncAssertSuccess(v -> started.complete())); started.awaitSuccess(10000); ctx.assertEquals(2, verticles.size()); ctx.assertNotEquals(verticles.get(0).server.getPort(), verticles.get(1).server.getPort()); } }
public VertxServer build() { ContextInternal context = vertx.getOrCreateContext(); return new VertxServer(id, options, builder, context); } }
void close(Handler<AsyncResult<Void>> h) { server.shutdown(h); }
@Test public void testRandomPort(TestContext ctx) throws Exception { Async started = ctx.async(); port = 0; startServer(new GreeterGrpc.GreeterVertxImplBase() { @Override public void sayHello(HelloRequest req, Future<HelloReply> future) { future.complete(HelloReply.newBuilder().setMessage("Hello " + req.getName()).build()); } }, ar -> { if (ar.succeeded()) { started.complete(); } else { ctx.fail(ar.cause()); } }); started.awaitSuccess(10000); ctx.assertTrue(server.getPort() > 0); ctx.assertTrue(server.getPort() < 65536); } }
@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(); } }); } }
@Override public void stop(Future<Void> stopFuture) throws Exception { server.shutdown(stopFuture.completer()); } }
@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(); } }); } }
public VertxServer start(Handler<AsyncResult<Void>> completionHandler) { if (id.port > 0) { actual = map.computeIfAbsent(id, id -> new ActualServer(context.owner(), id, options, builder)); } else { actual = new ActualServer(context.owner(), id, options, builder); } actual.start(context, ar1 -> { if (ar1.succeeded()) { hook = ar2 -> shutdown(); context.addCloseHook(hook); } completionHandler.handle(ar1); }); return this; }
rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace();
@After public void tearDown() throws Exception { if (server != null) { VertxServer s = server; server = null; CountDownLatch fut = new CountDownLatch(1); s.shutdown(ar -> fut.countDown()); fut.await(10, TimeUnit.SECONDS); } CountDownLatch latch = new CountDownLatch(1); vertx.close(ar -> latch.countDown()); latch.await(10, TimeUnit.SECONDS); }
@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(); } }); } }
rpcServer.start(ar -> { if (ar.failed()) { ar.cause().printStackTrace();
server.start(ar -> { if (ar.succeeded()) { System.out.println("gRPC service started");
@Override public void start() throws Exception { VertxServer server = VertxServerBuilder.forPort(vertx, 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()); } }) .useSsl(options -> options .setSsl(true) .setUseAlpn(true) .setKeyStoreOptions(new JksOptions() .setPath("tls/server-keystore.jks") .setPassword("wibble"))) .build(); server.start(ar -> { if (ar.succeeded()) { System.out.println("gRPC service started"); } else { System.out.println("Could not start server " + ar.cause().getMessage()); } }); } }
@Override public VertxServer start() throws IOException { return start(ar -> {}); }
void start(Handler<AsyncResult<Void>> h) { server.start(h); }
void startServer(BindableService service, VertxServerBuilder builder, Handler<AsyncResult<Void>> completionHandler) { server = builder .addService(service) .build() .start(completionHandler); } }
private void testInternal(TestContext ctx, Vertx vertx) { VertxServerBuilder.forPort(vertx, 0) .addService(new GreeterGrpc.GreeterImplBase() { }) .build() .start(ctx.asyncAssertSuccess()); }