io.grpc.ServerBuilder Java Examples

The following examples show how to use io.grpc.ServerBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DetailErrorSample.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
void run() throws Exception {
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      Metadata trailers = new Metadata();
      trailers.put(DEBUG_INFO_TRAILER_KEY, DEBUG_INFO);
      responseObserver.onError(Status.INTERNAL.withDescription(DEBUG_DESC)
          .asRuntimeException(trailers));
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
Example #2
Source File: CustomHeaderServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(PORT)
      .addService(ServerInterceptors.intercept(new GreeterImpl(), new HeaderServerInterceptor()))
      .build()
      .start();
  logger.info("Server started, listening on " + PORT);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      CustomHeaderServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #3
Source File: HelloJsonServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloJsonServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #4
Source File: ProtoApplication.java    From spring-graalvm-native with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
	/* The port on which the server should run */
	int port = 50051;
	server = ServerBuilder.forPort(port)
			.addService(ProtoReflectionService.newInstance())
			.addService(new GreeterImpl()).build().start();
	logger.info("Server started, listening on " + port);
	Runtime.getRuntime().addShutdownHook(new Thread() {
		@Override
		public void run() {
			// Use stderr here since the logger may have been reset by its JVM
			// shutdown hook.
			System.err.println(
					"*** shutting down gRPC server since JVM is shutting down");
			ProtoApplication.this.stop();
			System.err.println("*** server shut down");
		}
	});
}
 
Example #5
Source File: DetailErrorSample.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
void run() throws Exception {
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      Metadata trailers = new Metadata();
      trailers.put(DEBUG_INFO_TRAILER_KEY, DEBUG_INFO);
      responseObserver.onError(Status.INTERNAL.withDescription(DEBUG_DESC)
          .asRuntimeException(trailers));
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
Example #6
Source File: ErrorHandlingClient.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
void run() throws Exception {
  // Port 0 means that the operating system will pick an available port to use.
  Server server = ServerBuilder.forPort(0).addService(new GreeterGrpc.GreeterImplBase() {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
      responseObserver.onError(Status.INTERNAL
          .withDescription("Eggplant Xerxes Crybaby Overbite Narwhal").asRuntimeException());
    }
  }).build().start();
  channel =
      ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();

  blockingCall();
  futureCallDirect();
  futureCallCallback();
  asyncCall();
  advancedAsyncCall();

  channel.shutdown();
  server.shutdown();
  channel.awaitTermination(1, TimeUnit.SECONDS);
  server.awaitTermination();
}
 
Example #7
Source File: GrpcEmbeddedServer.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor.
 * @param applicationContext The application context
 * @param applicationConfiguration The application configuration
 * @param grpcServerConfiguration The GRPC server configuration
 * @param serverBuilder The server builder
 * @param eventPublisher The event publisher
 * @param computeInstanceMetadataResolver The computed instance metadata
 * @param metadataContributors The metadata contributors
 */
@Internal
GrpcEmbeddedServer(
        @Nonnull ApplicationContext applicationContext,
        @Nonnull ApplicationConfiguration applicationConfiguration,
        @Nonnull GrpcServerConfiguration grpcServerConfiguration,
        @Nonnull ServerBuilder<?> serverBuilder,
        @Nonnull ApplicationEventPublisher eventPublisher,
        @Nullable ComputeInstanceMetadataResolver computeInstanceMetadataResolver,
        @Nullable List<ServiceInstanceMetadataContributor> metadataContributors) {
    ArgumentUtils.requireNonNull("applicationContext", applicationContext);
    ArgumentUtils.requireNonNull("applicationConfiguration", applicationConfiguration);
    ArgumentUtils.requireNonNull("grpcServerConfiguration", grpcServerConfiguration);
    this.applicationContext = applicationContext;
    this.configuration = applicationConfiguration;
    this.grpcConfiguration = grpcServerConfiguration;
    this.eventPublisher = eventPublisher;
    this.server = serverBuilder.build();
    this.computeInstanceMetadataResolver = computeInstanceMetadataResolver;
    this.metadataContributors = metadataContributors;
}
 
Example #8
Source File: GoalStateProvisionerServer.java    From alcor with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
    /* The port on which the server should run */
    int port = 50051;
    server = ServerBuilder.forPort(port)
            .addService(new GoalStateProvisionerImpl())
            .build()
            .start();
    Logger logger = LoggerFactory.getLogger();
    logger.log(Level.INFO, "GoalStateProvisionerServer : Server started, listening on ");
    logger.log(Level.INFO, "Server started, listening on " + port);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // Use stderr here since the logger may have been reset by its JVM shutdown hook.
            logger.log(Level.SEVERE, "*** shutting down gRPC server since JVM is shutting down");
            GoalStateProvisionerServer.this.stop();
            logger.log(Level.SEVERE, "*** server shut down");
        }
    });
}
 
Example #9
Source File: LocalServer.java    From startup-os with Apache License 2.0 6 votes vote down vote up
@Inject
LocalServer(
    @Named("Server log path") String logPath,
    AuthService authService,
    CodeReviewService codeReviewService) {
  if (logToFile.get()) {
    // TODO: Figure out how to also direct Flogger to log file.
    try {
      PrintStream logStream = new PrintStream(logPath);
      System.setOut(logStream);
      System.setErr(logStream);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
  server =
      ServerBuilder.forPort(localServerPort.get())
          .addService(authService)
          .addService(codeReviewService)
          .addService(ProtoReflectionService.newInstance())
          .build();
}
 
Example #10
Source File: GraknTestServer.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
private Server createServer() {
    // distributed locks
    LockManager lockManager = new LockManager();
    JanusGraphFactory janusGraphFactory = new JanusGraphFactory(serverConfig);
    HadoopGraphFactory hadoopGraphFactory = new HadoopGraphFactory(serverConfig);

    Integer storagePort = serverConfig.getProperty(ConfigKey.STORAGE_PORT);
    String storageHostname = serverConfig.getProperty(ConfigKey.STORAGE_HOSTNAME);
    // CQL cluster used by KeyspaceManager to fetch all existing keyspaces
    CqlSession cqlSession = CqlSession.builder()
            .addContactPoint(new InetSocketAddress(storageHostname, storagePort))
            .withLocalDatacenter("datacenter1")
            .build();

    sessionFactory = new SessionFactory(lockManager, janusGraphFactory, hadoopGraphFactory, serverConfig);
    keyspaceManager = new KeyspaceManager(cqlSession, janusGraphFactory, sessionFactory);

    OpenRequest requestOpener = new ServerOpenRequest(sessionFactory);

    io.grpc.Server serverRPC = ServerBuilder.forPort(grpcPort)
            .addService(new SessionService(requestOpener))
            .addService(new KeyspaceService(keyspaceManager))
            .build();

    return ServerFactory.createServer(serverRPC);
}
 
Example #11
Source File: HelloServer.java    From spring-boot-demo with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
    // 使用ServerBuilder来构建和启动服务,通过使用forPort方法来指定监听的地址和端口
    // 创建一个实现方法的服务GreeterImpl的实例,并通过addService方法将该实例纳入
    // 调用build() start()方法构建和启动rpcserver
    server = ServerBuilder.forPort(port)
            .addService(new GreeterImpl())
            .build()
            .start();
    logger.info("Server started, listening on " + port);

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // Use stderr here since the logger may have been reset by its JVM shutdown hook.
            System.err.println("*** shutting down gRPC server since JVM is shutting down");
            HelloServer.this.stop();
            System.err.println("*** server shut down");
        }
    });
}
 
Example #12
Source File: BaseITTracingServerInterceptor.java    From brave with Apache License 2.0 6 votes vote down vote up
void init(@Nullable ServerInterceptor userInterceptor) throws IOException {
  stop();

  // tracing interceptor needs to go last
  ServerInterceptor tracingInterceptor = grpcTracing.newServerInterceptor();
  ServerInterceptor[] interceptors = userInterceptor != null
      ? new ServerInterceptor[] {userInterceptor, tracingInterceptor}
      : new ServerInterceptor[] {tracingInterceptor};

  server = ServerBuilder.forPort(PickUnusedPort.get())
      .addService(ServerInterceptors.intercept(new GreeterImpl(grpcTracing), interceptors))
      .build().start();

  client = usePlainText(ManagedChannelBuilder.forAddress("localhost", server.getPort()))
      .build();
}
 
Example #13
Source File: HelloWorldServer.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloWorldServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #14
Source File: CompressingHelloWorldServerPerMethod.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      try {
        CompressingHelloWorldServerPerMethod.this.stop();
      } catch (InterruptedException e) {
        e.printStackTrace(System.err);
      }
      System.err.println("*** server shut down");
    }
  });
}
 
Example #15
Source File: GRpcAutoConfiguration.java    From grpc-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Bean(name = "grpcInternalConfigurator")
public Consumer<ServerBuilder<?>> configurator(GRpcServerBuilderConfigurer configurer){
    return serverBuilder -> {
        if(grpcServerProperties.isEnabled()){
            Optional.ofNullable(grpcServerProperties.getSecurity())
                    .ifPresent(s->{
                        boolean setupSecurity = Optional.ofNullable(s.getCertChain()).isPresent();
                        if(setupSecurity != Optional.ofNullable(s.getPrivateKey()).isPresent() ){
                            throw  new BeanCreationException("Both  gRPC  TLS 'certChain' and 'privateKey' should be configured. One of them is null. ");
                        }
                        if(setupSecurity) {
                            try {
                                serverBuilder.useTransportSecurity(s.getCertChain().getInputStream(),
                                        s.getPrivateKey().getInputStream()
                                );
                            } catch (IOException e) {
                                throw new BeanCreationException("Failed to setup security", e);
                            }
                        }
                    });
        }
        configurer.configure(serverBuilder);
    };
}
 
Example #16
Source File: GRPCServer.java    From pravega with Apache License 2.0 6 votes vote down vote up
/**
 * Create gRPC server on the specified port.
 *
 * @param controllerService The controller service implementation.
 * @param serverConfig      The RPC Server config.
 * @param requestTracker    Cache to track and access to client request identifiers.
 */
public GRPCServer(ControllerService controllerService, GRPCServerConfig serverConfig, RequestTracker requestTracker) {
    this.objectId = "gRPCServer";
    this.config = serverConfig;
    GrpcAuthHelper authHelper = new GrpcAuthHelper(serverConfig.isAuthorizationEnabled(),
            serverConfig.getTokenSigningKey(), serverConfig.getAccessTokenTTLInSeconds());
    ServerBuilder<?> builder = ServerBuilder
            .forPort(serverConfig.getPort())
            .addService(ServerInterceptors.intercept(new ControllerServiceImpl(controllerService, authHelper, requestTracker,
                            serverConfig.isReplyWithStackTraceOnError()),
                    RPCTracingHelpers.getServerInterceptor(requestTracker)));
    if (serverConfig.isAuthorizationEnabled()) {
        this.authHandlerManager = new AuthHandlerManager(serverConfig);
        this.authHandlerManager.registerInterceptors(builder);
    } else {
        this.authHandlerManager = null;
    }

    if (serverConfig.isTlsEnabled() && !Strings.isNullOrEmpty(serverConfig.getTlsCertFile())) {
        builder = builder.useTransportSecurity(new File(serverConfig.getTlsCertFile()),
                new File(serverConfig.getTlsKeyFile()));
    }
    this.server = builder.build();
}
 
Example #17
Source File: ProtoApplication.java    From spring-boot-graal-feature with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
	/* The port on which the server should run */
	int port = 50051;
	server = ServerBuilder.forPort(port)
			.addService(ProtoReflectionService.newInstance())
			.addService(new GreeterImpl()).build().start();
	logger.info("Server started, listening on " + port);
	Runtime.getRuntime().addShutdownHook(new Thread() {
		@Override
		public void run() {
			// Use stderr here since the logger may have been reset by its JVM
			// shutdown hook.
			System.err.println(
					"*** shutting down gRPC server since JVM is shutting down");
			ProtoApplication.this.stop();
			System.err.println("*** server shut down");
		}
	});
}
 
Example #18
Source File: HelloWorldServer2.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
          .addService(new GreeterImpl())
          .build()
          .start();

  logger.info("Server started, listening on " + port);

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      HelloWorldServer2.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #19
Source File: EventGrpcServer.java    From julongchain with Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
    server = ServerBuilder.forPort(port)
            .addService(new EventServerImpl())
            .build()
            .start();
    log.info("EventGrpcServer start, port: " + port);

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            log.info("Shutting down EventGrpcServer since JVM is shutting down");
            EventGrpcServer.this.stop();
            log.error("EventGrpcServer shut down");
        }
    });
}
 
Example #20
Source File: ConsumerTestServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
  server = ServerBuilder.forPort(port)
          .addService(new GreeterImpl2(port))
          .build()
          .start();

  logger.info("ConsumerTestServer start...");

  Runtime.getRuntime().addShutdownHook(new Thread() {

    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      ConsumerTestServer.this.stop();
      System.err.println("*** ConsumerTestServer shut down");
    }
  });
}
 
Example #21
Source File: RetryingHelloWorldServer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);

  DecimalFormat df = new DecimalFormat("#%");
  logger.info("Responding as UNAVAILABLE to " + df.format(UNAVAILABLE_PERCENTAGE) + " requests");
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      try {
        RetryingHelloWorldServer.this.stop();
      } catch (InterruptedException e) {
        e.printStackTrace(System.err);
      }
      System.err.println("*** server shut down");
    }
  });
}
 
Example #22
Source File: GrpcServer.java    From spring-boot-starter-grpc with MIT License 6 votes vote down vote up
/**
 * 启动服务
 * @throws Exception 异常
 */
public void start() throws Exception{
    int port = grpcProperties.getPort();
    if (serverInterceptor != null){
        server = ServerBuilder.forPort(port).addService(ServerInterceptors.intercept(commonService, serverInterceptor)).build().start();
    }else {
        Class clazz = grpcProperties.getServerInterceptor();
        if (clazz == null){
            server = ServerBuilder.forPort(port).addService(commonService).build().start();
        }else {
            server = ServerBuilder.forPort(port).addService(ServerInterceptors.intercept(commonService, (ServerInterceptor) clazz.newInstance())).build().start();
        }
    }
    log.info("gRPC Server started, listening on port " + server.getPort());
    startDaemonAwaitThread();
}
 
Example #23
Source File: PersonServiceServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
  server = ServerBuilder.forPort(port)
          .addService(new PersonNameImpl())
          .addService(new PersonAgeImpl())
          .addService(new PersonSalaryImpl())
          .addService(new PersonInfoImpl())
          .build()
          .start();

  logger.info("PersonServiceServer start...");

  Runtime.getRuntime().addShutdownHook(new Thread() {

    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      PersonServiceServer.this.stop();
      System.err.println("*** PersonServiceServer shut down");
    }
  });
}
 
Example #24
Source File: CustomHeaderServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(PORT)
      .addService(ServerInterceptors.intercept(new GreeterImpl(), new HeaderServerInterceptor()))
      .build()
      .start();
  logger.info("Server started, listening on " + PORT);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      CustomHeaderServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #25
Source File: HelloJsonServer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      try {
        HelloJsonServer.this.stop();
      } catch (InterruptedException e) {
        e.printStackTrace(System.err);
      }
      System.err.println("*** server shut down");
    }
  });
}
 
Example #26
Source File: CommonServiceSecondServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
public void start() throws IOException {
  serviceImpl = new GreeterImpl();

  server = ServerBuilder.forPort(port)
          .addService(serviceImpl)
          .build()
          .start();

  logger.info("CommonServiceSecondServer start...");

  Runtime.getRuntime().addShutdownHook(new Thread() {

    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      CommonServiceSecondServer.this.stop();
      System.err.println("*** CommonServiceFirstServer shut down");
    }
  });
}
 
Example #27
Source File: AuthServer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  server = ServerBuilder.forPort(port)
      .addService(new GreeterImpl())
      .intercept(new JwtServerInterceptor())  // add the JwtServerInterceptor
      .build()
      .start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      // Use stderr here since the logger may have been reset by its JVM shutdown hook.
      System.err.println("*** shutting down gRPC server since JVM is shutting down");
      AuthServer.this.stop();
      System.err.println("*** server shut down");
    }
  });
}
 
Example #28
Source File: HelloWorldServer.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
  /* The port on which the server should run */
  int port = 50051;
  server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
  logger.info("Server started, listening on " + port);
  Runtime.getRuntime()
      .addShutdownHook(
          new Thread() {
            @Override
            public void run() {
              // Use stderr here since the logger may have been reset by its JVM shutdown hook.
              System.err.println("*** shutting down gRPC server since JVM is shutting down");
              HelloWorldServer.this.stop();
              System.err.println("*** server shut down");
            }
          });
}
 
Example #29
Source File: UpstreamSimpleBenchmark.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
    server = ServerBuilder.forPort(0)
                          .addService(new GithubApiService())
                          .directExecutor()
                          .build();
    server.start();
    channel = ManagedChannelBuilder.forAddress("127.0.0.1", port())
                                   .directExecutor()
                                   .usePlaintext()
                                   .build();
    githubApiClient = GithubServiceGrpc.newBlockingStub(channel);
    githubApiFutureClient = GithubServiceGrpc.newFutureStub(channel);
}
 
Example #30
Source File: UnimplementedMethodIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
public static void setupServer() throws Exception {
    ReactorGreeterGrpc.GreeterImplBase svc = new ReactorGreeterGrpc.GreeterImplBase() {
        // Don't implement anything
    };

    server = ServerBuilder.forPort(9000).addService(svc).build().start();
    channel = ManagedChannelBuilder.forAddress("localhost", server.getPort()).usePlaintext().build();
}