本文整理汇总了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;
}
示例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();
}