io.grpc.netty.shaded.io.grpc.netty.NegotiationType Java Examples
The following examples show how to use
io.grpc.netty.shaded.io.grpc.netty.NegotiationType.
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: DefaultPubSubSubscriberFactory.java From flink with Apache License 2.0 | 6 votes |
@Override public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException { ManagedChannel channel = NettyChannelBuilder.forTarget(SubscriberStubSettings.getDefaultEndpoint()) .negotiationType(NegotiationType.TLS) .sslContext(GrpcSslContexts.forClient().ciphers(null).build()) .build(); PullRequest pullRequest = PullRequest.newBuilder() .setMaxMessages(maxMessagesPerPull) .setReturnImmediately(false) .setSubscription(projectSubscriptionName) .build(); SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel) .withCallCredentials(MoreCallCredentials.from(credentials)); return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout); }
Example #2
Source File: GrpcConnectionPool.java From FATE-Serving with Apache License 2.0 | 6 votes |
public synchronized ManagedChannel createManagedChannel(String ip, int port) throws Exception { if (logger.isDebugEnabled()) { logger.debug("create ManagedChannel"); } NettyChannelBuilder builder = NettyChannelBuilder .forAddress(ip, port) .keepAliveTime(60, TimeUnit.SECONDS) .keepAliveTimeout(60, TimeUnit.SECONDS) .keepAliveWithoutCalls(true) .idleTimeout(60, TimeUnit.SECONDS) .perRpcBufferLimit(128 << 20) .flowControlWindow(32 << 20) .maxInboundMessageSize(32 << 20) .enableRetry() .retryBufferSize(16 << 20) .maxRetryAttempts(20); // todo: configurable builder.negotiationType(NegotiationType.PLAINTEXT) .usePlaintext(); return builder.build(); }
Example #3
Source File: ReactorToGrpcClientBuilderTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { this.sampleService = new SampleServiceImpl(); this.server = NettyServerBuilder.forPort(0) .addService(ServerInterceptors.intercept(sampleService, new SampleContextServerInterceptor())) .build() .start(); this.channel = NettyChannelBuilder.forTarget("localhost:" + server.getPort()) .negotiationType(NegotiationType.PLAINTEXT) .build(); this.client = ReactorToGrpcClientBuilder.newBuilder(SampleServiceReactorClient.class, SampleServiceGrpc.newStub(channel), SampleServiceGrpc.getServiceDescriptor(), SampleContext.class) .withTimeout(TIMEOUT_DURATION) .withStreamingTimeout(Duration.ofMillis(ReactorToGrpcClientBuilder.DEFAULT_STREAMING_TIMEOUT_MS)) .withGrpcStubDecorator(SampleContextServerInterceptor::attachClientContext) .build(); }
Example #4
Source File: GrpcToReactorServerBuilderTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
private void createReactorGrpcServer(ReactorSampleServiceImpl reactorSampleService) throws Exception { this.reactorSampleService = reactorSampleService; DefaultGrpcToReactorServerFactory<SampleContext> factory = new DefaultGrpcToReactorServerFactory<>(SampleContext.class, SampleContextServerInterceptor::serverResolve); ServerServiceDefinition serviceDefinition = factory.apply(SampleServiceGrpc.getServiceDescriptor(), reactorSampleService, ReactorSampleServiceImpl.class); this.server = NettyServerBuilder.forPort(0) .addService(ServerInterceptors.intercept(serviceDefinition, new SampleContextServerInterceptor())) .build() .start(); this.channel = NettyChannelBuilder.forTarget("localhost:" + server.getPort()) .negotiationType(NegotiationType.PLAINTEXT) .build(); this.client = ReactorToGrpcClientBuilder.newBuilder(SampleServiceReactorClient.class, SampleServiceGrpc.newStub(channel), SampleServiceGrpc.getServiceDescriptor(), SampleContext.class) .withTimeout(TIMEOUT_DURATION) .withStreamingTimeout(Duration.ofMillis(ReactorToGrpcClientBuilder.DEFAULT_STREAMING_TIMEOUT_MS)) .withGrpcStubDecorator(SampleContextServerInterceptor::attachClientContext) .build(); }
Example #5
Source File: DefaultPubSubSubscriberFactory.java From flink with Apache License 2.0 | 6 votes |
@Override public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException { ManagedChannel channel = NettyChannelBuilder.forTarget(SubscriberStubSettings.getDefaultEndpoint()) .negotiationType(NegotiationType.TLS) .sslContext(GrpcSslContexts.forClient().ciphers(null).build()) .build(); PullRequest pullRequest = PullRequest.newBuilder() .setMaxMessages(maxMessagesPerPull) .setReturnImmediately(false) .setSubscription(projectSubscriptionName) .build(); SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(channel) .withCallCredentials(MoreCallCredentials.from(credentials)); return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, channel, stub, pullRequest, retries, timeout); }
Example #6
Source File: GrpcExecutionFactory.java From buck with Apache License 2.0 | 6 votes |
private static NettyChannelBuilder createSecureChannel( String host, int port, Optional<Path> certPath, Optional<Path> keyPath, Optional<Path> caPath) throws SSLException { SslContextBuilder contextBuilder = GrpcSslContexts.forClient(); if (certPath.isPresent() && keyPath.isPresent()) { contextBuilder.keyManager(certPath.get().toFile(), keyPath.get().toFile()); } if (caPath.isPresent()) { contextBuilder.trustManager(caPath.get().toFile()); } return channelBuilder(host, port) .sslContext(contextBuilder.build()) .negotiationType(NegotiationType.TLS); }
Example #7
Source File: ClientGrpcConfig.java From flair-engine with Apache License 2.0 | 4 votes |
private ManagedChannelFactory createManagedChannelFactory(String serviceName, boolean tlsEnabled, String trustCertCollectionFile, String clientCertChainFile, String clientPrivateKeyFile) { Supplier<ManagedChannel> dynamicManagedChannel = () -> { NettyChannelBuilder nettyChannelBuilder; if (flairCachingConfig.getUrl() == null) { InstanceInfo instanceInfo = client.getNextServerFromEureka(serviceName, false); nettyChannelBuilder = NettyChannelBuilder.forAddress( tlsEnabled ? instanceInfo.getHostName() : instanceInfo.getIPAddr(), instanceInfo.getPort()); log.info("GRPC config: Hostname {} IP {} port {} secure port {} secure vip {}", instanceInfo.getHostName(), instanceInfo.getIPAddr(), instanceInfo.getPort(), instanceInfo.getSecurePort(), instanceInfo.getSecureVipAddress()); } else { nettyChannelBuilder = NettyChannelBuilder.forTarget(flairCachingConfig.getUrl()); log.info("GRPC config: Hostname url {}", flairCachingConfig.getUrl()); } if (tlsEnabled) { nettyChannelBuilder.negotiationType(NegotiationType.TLS); log.info("GRPC config: GRPC TLS enabled"); try { nettyChannelBuilder.sslContext(buildSslContext( trustCertCollectionFile, clientCertChainFile, clientPrivateKeyFile )); } catch (SSLException e) { log.error("GRPC config: error", e); } } else { nettyChannelBuilder.usePlaintext(); } return nettyChannelBuilder.build(); }; return new ManagedChannelFactory(dynamicManagedChannel); }