当前位置: 首页>>代码示例>>Java>>正文


Java NettyChannelBuilder.intercept方法代码示例

本文整理汇总了Java中io.grpc.netty.NettyChannelBuilder.intercept方法的典型用法代码示例。如果您正苦于以下问题:Java NettyChannelBuilder.intercept方法的具体用法?Java NettyChannelBuilder.intercept怎么用?Java NettyChannelBuilder.intercept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.grpc.netty.NettyChannelBuilder的用法示例。


在下文中一共展示了NettyChannelBuilder.intercept方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: defaultChannelBuilder

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
private ManagedChannelBuilder<?> defaultChannelBuilder() {
  NettyChannelBuilder channelBuilder = NettyChannelBuilder.forTarget("etcd");

  if (builder.sslContext() != null) {
    channelBuilder.sslContext(builder.sslContext());
  } else {
    channelBuilder.usePlaintext(true);
  }

  channelBuilder.nameResolverFactory(
      forEndpoints(
        Optional.ofNullable(builder.authority()).orElse("etcd"),
        builder.endpoints(),
        Optional.ofNullable(builder.uriResolverLoader())
            .orElseGet(URIResolverLoader::defaultLoader)
      )
  );

  if (builder.loadBalancerFactory() != null) {
    channelBuilder.loadBalancerFactory(builder.loadBalancerFactory());
  }

  channelBuilder.intercept(new AuthTokenInterceptor());

  return channelBuilder;
}
 
开发者ID:coreos,项目名称:jetcd,代码行数:27,代码来源:ClientConnectionManager.java

示例2: createNettyChannel

import io.grpc.netty.NettyChannelBuilder; //导入方法依赖的package包/类
/**
 * <p>
 * createNettyChannel.
 * </p>
 *
 * @param interceptors a {@link List} object.
 * @param globalClientOptions a {@link ClientOptions} object.
 * @return a {@link ManagedChannel} object.
 * @throws SSLException if any.
 * @throws IOException if any.
 */
private ManagedChannel createNettyChannel(ClientOptions clientOptions, List<ClientInterceptor> interceptors) throws SSLException, IOException {
 
  NettyChannelBuilder builder = NettyChannelBuilder.forTarget(clientOptions.getServiceEndpoint());
  // 这里要注意下由于java版本的没有提供像go那样的可以指定域名
  // java版本源代码中把host传入作为证书域名
  // 域名是在证书生成的过程中自己输入的
  //String serverHostOverride = "localhost";
  if (clientOptions.getServerHostOverride() != null) {
    // Force the hostname to match the cert the server uses.
    builder.overrideAuthority(clientOptions.getServerHostOverride());
  }
  if (clientOptions.isUsedTls()) {
    builder
        .sslContext(
            GrpcSslContexts.forClient().trustManager(SslUtils.loadCert("server.pem")).build())
        .negotiationType(NegotiationType.TLS);
  }   
  builder
      .nameResolverFactory(AbstractNameResolverProvider.provider()
              .withRegistryCenterAddress(clientOptions.getRegistryCenterAddress())
              .withZoneToPrefer(clientOptions.getZoneToPrefer())
              .withServiceEndpoint(clientOptions.getServiceEndpoint())
              .withUsedTls(clientOptions.isUsedTls()))
      .loadBalancerFactory(GrpclbLoadBalancerFactory.getInstance())
      //The TCP connections are shutdown when you shutdown the Channel. 
      //Specify an idleTimeout() to have the Channel automatically close the TCP connection after a period of inactivity.
      .idleTimeout(Long.MAX_VALUE, TimeUnit.SECONDS)
      .maxInboundMessageSize(MAX_MESSAGE_SIZE)
      //.sslContext(createSslContext())
      //TODO: Caused run unit testing error happen in maven if comment out below 1 line code!!!
      //.eventLoopGroup(RpcSharedThreadPools.getInstance().getElg())
      .executor(RpcSharedThreadPools.getInstance().getBatchThreadPool())
      // .userAgent(VersionInfo.CORE_UESR_AGENT + "," + options.getUserAgent())
      .flowControlWindow(FLOW_CONTROL_WINDOW)
      .intercept(new HeaderClientInterceptor(),
          new StubDeadlineClientInterceptor());
  if(interceptors != null && interceptors.size() > 0){
    builder.intercept(interceptors);
  }
  return builder.build();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:53,代码来源:GrpcClientInitializer.java


注:本文中的io.grpc.netty.NettyChannelBuilder.intercept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。