Search in sources :

Example 6 with NettyChannelBuilder

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.netty.NettyChannelBuilder in project pinpoint by naver.

the class DefaultChannelFactory method build.

@Override
public ManagedChannel build(String channelName, String host, int port) {
    final NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
    channelBuilder.usePlaintext();
    logger.info("ChannelType:{}", channelType.getSimpleName());
    channelBuilder.channelType(channelType);
    channelBuilder.eventLoopGroup(eventLoopGroup);
    setupInternal(channelBuilder);
    channelBuilder.defaultLoadBalancingPolicy(GrpcUtil.DEFAULT_LB_POLICY);
    addHeader(channelBuilder);
    addClientInterceptor(channelBuilder);
    channelBuilder.executor(executorService);
    if (nameResolverProvider != null) {
        logger.info("Set nameResolverProvider {}. channelName={}, host={}, port={}", this.nameResolverProvider, channelName, host, port);
        setNameResolverFactory(channelBuilder, this.nameResolverProvider);
    }
    setupClientOption(channelBuilder);
    if (sslClientConfig.isEnable()) {
        SslContext sslContext = null;
        try {
            sslContext = SslContextFactory.create(sslClientConfig);
        } catch (SSLException e) {
            throw new SecurityException(e);
        }
        channelBuilder.sslContext(sslContext);
        channelBuilder.negotiationType(NegotiationType.TLS);
    }
    channelBuilder.maxTraceEvents(clientOption.getMaxTraceEvent());
    final ManagedChannel channel = channelBuilder.build();
    return channel;
}
Also used : InternalNettyChannelBuilder(io.grpc.netty.InternalNettyChannelBuilder) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) ManagedChannel(io.grpc.ManagedChannel) SSLException(javax.net.ssl.SSLException) SslContext(io.netty.handler.ssl.SslContext)

Example 7 with NettyChannelBuilder

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.netty.NettyChannelBuilder in project alluxio by Alluxio.

the class GrpcConnectionPool method createManagedChannel.

/**
 * Creates a {@link ManagedChannel} by given pool key.
 */
private ManagedChannel createManagedChannel(GrpcChannelKey channelKey, AlluxioConfiguration conf) {
    // Create netty channel builder with the address from channel key.
    NettyChannelBuilder channelBuilder;
    SocketAddress address = channelKey.getServerAddress().getSocketAddress();
    if (address instanceof InetSocketAddress) {
        InetSocketAddress inetServerAddress = (InetSocketAddress) address;
        // This constructor delays DNS lookup to detect changes
        channelBuilder = NettyChannelBuilder.forAddress(inetServerAddress.getHostName(), inetServerAddress.getPort());
    } else {
        channelBuilder = NettyChannelBuilder.forAddress(address);
    }
    // Apply default channel options for the multiplex group.
    channelBuilder = applyGroupDefaults(channelKey, channelBuilder, conf);
    // Build netty managed channel.
    return channelBuilder.build();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 8 with NettyChannelBuilder

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.netty.NettyChannelBuilder in project grpc-java by grpc.

the class Http2NettyTest method createChannelBuilder.

@Override
protected NettyChannelBuilder createChannelBuilder() {
    try {
        ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key")).trustManager(TestUtils.loadCert("ca.pem")).build();
        NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", ((InetSocketAddress) getListenAddress()).getPort(), channelCreds).overrideAuthority(TestUtils.TEST_SERVER_HOST).flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
        // Disable the default census stats interceptor, use testing interceptor instead.
        InternalNettyChannelBuilder.setStatsEnabled(builder, false);
        return builder.intercept(createCensusStatsClientInterceptor());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ChannelCredentials(io.grpc.ChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) InetSocketAddress(java.net.InetSocketAddress) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) InternalNettyChannelBuilder(io.grpc.netty.InternalNettyChannelBuilder) IOException(java.io.IOException)

Example 9 with NettyChannelBuilder

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.netty.NettyChannelBuilder in project grpc-java by grpc.

the class AutoWindowSizingOnTest method createChannelBuilder.

@Override
protected NettyChannelBuilder createChannelBuilder() {
    NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress()).negotiationType(NegotiationType.PLAINTEXT).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).initialFlowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW);
    // Disable the default census stats interceptor, use testing interceptor instead.
    InternalNettyChannelBuilder.setStatsEnabled(builder, false);
    return builder.intercept(createCensusStatsClientInterceptor());
}
Also used : NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) InternalNettyChannelBuilder(io.grpc.netty.InternalNettyChannelBuilder)

Example 10 with NettyChannelBuilder

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.netty.NettyChannelBuilder in project dubbo by alibaba.

the class GrpcOptionsUtils method buildManagedChannel.

static ManagedChannel buildManagedChannel(URL url) {
    NettyChannelBuilder builder = NettyChannelBuilder.forAddress(url.getHost(), url.getPort());
    if (url.getParameter(SSL_ENABLED_KEY, false)) {
        builder.sslContext(buildClientSslContext(url));
    } else {
        builder.usePlaintext();
    }
    builder.disableRetry();
    // builder.directExecutor();
    // client interceptors
    List<io.grpc.ClientInterceptor> interceptors = new ArrayList<>(ExtensionLoader.getExtensionLoader(ClientInterceptor.class).getActivateExtension(url, CLIENT_INTERCEPTORS, CONSUMER_SIDE));
    builder.intercept(interceptors);
    return getConfigurator().map(configurator -> configurator.configureChannelBuilder(builder, url)).orElse(builder).build();
}
Also used : ClientInterceptor(org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor) ArrayList(java.util.ArrayList) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder)

Aggregations

NettyChannelBuilder (io.grpc.netty.NettyChannelBuilder)20 InternalNettyChannelBuilder (io.grpc.netty.InternalNettyChannelBuilder)6 InetSocketAddress (java.net.InetSocketAddress)4 ByteString (com.google.protobuf.ByteString)3 ManagedChannel (io.grpc.ManagedChannel)3 Metadata (io.grpc.Metadata)3 LocalAddress (io.netty.channel.local.LocalAddress)3 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)3 CallOptions (io.grpc.CallOptions)2 Channel (io.grpc.Channel)2 ClientCall (io.grpc.ClientCall)2 ClientInterceptor (io.grpc.ClientInterceptor)2 ForwardingClientCall (io.grpc.ForwardingClientCall)2 ForwardingClientCallListener (io.grpc.ForwardingClientCallListener)2 MethodDescriptor (io.grpc.MethodDescriptor)2 Listener (io.grpc.ServerCall.Listener)2 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SslContext (io.netty.handler.ssl.SslContext)2 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)2