/** * Add brave's client interceptor to the builder. */ @Override public void customize(ManagedChannelBuilder<?> managedChannelBuilder) { managedChannelBuilder.intercept(this.grpcTracing.newClientInterceptor()); }
private HelloWorldClientProcess(ManagedChannelBuilder<?> channelBuilder) { channel = channelBuilder.intercept(new ClientInterruptImpl()).build(); //使用gzip压缩 blockingStub = GreeterGrpc.newBlockingStub(channel).withCompression("gzip"); }
/** * Add brave's client interceptor to the builder. */ @Override public void customize(ManagedChannelBuilder<?> managedChannelBuilder) { managedChannelBuilder.intercept(this.grpcTracing.newClientInterceptor()); }
@Override public T intercept(List<ClientInterceptor> interceptors) { delegate().intercept(interceptors); return thisT(); }
@Override public T intercept(ClientInterceptor... interceptors) { delegate().intercept(interceptors); return thisT(); }
@Override public T intercept(List<ClientInterceptor> interceptors) { delegate().intercept(interceptors); return thisT(); }
@Override public T intercept(ClientInterceptor... interceptors) { delegate().intercept(interceptors); return thisT(); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress(getHostname(), getPort()); builder.executor(getServerExecutor()); builder.usePlaintext().intercept(getTenantTokenInterceptor()).intercept(getJwtInterceptor()); if (isUseTracingInterceptor()) { builder.intercept(getTracingInterceptor()); } this.channel = builder.build(); this.blockingStub = createBlockingStub(); this.asyncStub = createAsyncStub(); }
public static void main(String[] args) { ManagedChannel goodbyeChannel = ManagedChannelBuilder.forAddress("localhost", 9090) .usePlaintext(true) .intercept(new BraveGrpcClientInterceptor(Constant.brave("client-example"))) .intercept(MonitoringClientInterceptor.create(Configuration.allMetrics())) .build(); for (int i = 0; i < 100; i++) { GoodbyeServiceGrpc.GoodbyeServiceBlockingStub stub = GoodbyeServiceGrpc.newBlockingStub(goodbyeChannel); GoodbyeResponse goodbye = stub.goodbye(GoodbyeRequest.newBuilder().setName("Ray").build()); System.out.println(goodbye); } goodbyeChannel.shutdownNow(); } }
static public void main(String[] args) throws IOException, InterruptedException { JwtServerInterceptor jwtInterceptor = new JwtServerInterceptor(Constant.JWT_SECRET); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new JwtClientInterceptor()) .intercept(new TraceIdClientInterceptor()) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel); Server goodbyeServer = ServerBuilder.forPort(9090) .addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub), jwtInterceptor, new TraceIdServerInterceptor())) .build(); goodbyeServer.start(); System.out.println("Server started!"); goodbyeServer.awaitTermination(); }
builder.intercept(interceptorProvider.getInterceptors());
public static void main(String[] args) { String jwt = createJwt(Constant.JWT_SECRET, "authClient", "rayt"); //String jwt = createJwt("123124123", "authClient", "rayt"); System.out.println("Created a JWT: " + jwt); JwtCallCredential callCredential = new JwtCallCredential(jwt); ManagedChannel greetingChannel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new TraceIdClientInterceptor()) .build(); ManagedChannel goodbyeChannel = ManagedChannelBuilder.forAddress("localhost", 9090) .usePlaintext(true) .intercept(new TraceIdClientInterceptor()) .build(); Context.current().withValue(Constant.TRACE_ID_CTX_KEY, "1").run(() -> { GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(greetingChannel).withCallCredentials(callCredential); HelloResponse helloResponse = greetingStub.greeting(HelloRequest.newBuilder().setName("Ray").build()); System.out.println(helloResponse); }); Context.current().withValue(Constant.TRACE_ID_CTX_KEY, "2").run(() -> { GoodbyeServiceGrpc.GoodbyeServiceBlockingStub goodbyeStub = GoodbyeServiceGrpc.newBlockingStub(goodbyeChannel).withCallCredentials(callCredential); GoodbyeResponse goodbyeResponse = goodbyeStub.goodbye(GoodbyeRequest.newBuilder().setName("Jason").build()); System.out.println(goodbyeResponse); }); }
channelBuilder = channelBuilder.intercept(RPCTracingHelpers.getClientInterceptor());
/** * <p>createNettyChannel.</p> * * @param host a {@link String} object. * @param options a {@link BigtableOptions} object. * @return a {@link ManagedChannel} object. * @throws SSLException if any. */ public static ManagedChannel createNettyChannel(String host, BigtableOptions options, ClientInterceptor ... interceptors) throws SSLException { // Ideally, this should be ManagedChannelBuilder.forAddress(...) rather than an explicit // call to NettyChannelBuilder. Unfortunately, that doesn't work for shaded artifacts. ManagedChannelBuilder<?> builder = ManagedChannelBuilder .forAddress(host, options.getPort()); if (options.usePlaintextNegotiation()) { // NOTE: usePlaintext(true) is deprecated in newer versions of grpc (1.11.0). // usePlantxext() is the preferred approach, but won't work with older versions. // This means that plaintext negotiation can't be used with Beam. builder.usePlaintext(); } return builder .idleTimeout(Long.MAX_VALUE, TimeUnit.SECONDS) .maxInboundMessageSize(MAX_MESSAGE_SIZE) .userAgent(BigtableVersionInfo.CORE_USER_AGENT + "," + options.getUserAgent()) .intercept(interceptors) .build(); }
static public void main(String[] args) throws IOException, InterruptedException { Brave brave = Constant.brave("goodbye-service"); ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) .usePlaintext(true) .intercept(new BraveGrpcClientInterceptor(brave)) .build(); GreetingServiceGrpc.GreetingServiceBlockingStub greetingStub = GreetingServiceGrpc.newBlockingStub(channel); Server goodbyeServer = ServerBuilder.forPort(9090) .addService(ServerInterceptors.intercept(new GoodbyeServiceImpl(greetingStub), new BraveGrpcServerInterceptor(brave), MonitoringServerInterceptor.create(Configuration.allMetrics()))) .build(); goodbyeServer.start(); PrometheusServer prometheusServer = new PrometheusServer(CollectorRegistry.defaultRegistry, 8081); prometheusServer.start(); System.out.println("Server started!"); goodbyeServer.awaitTermination(); prometheusServer.shutdown(); }
@Override public TransportChannel getTransportChannel() throws IOException { ManagedChannelBuilder channelBuilder = InProcessChannelBuilder.forName(address).usePlaintext(); if (headerProvider != null) { GrpcHeaderInterceptor interceptor = new GrpcHeaderInterceptor(headerProvider.getHeaders()); LocalHeaderInterceptor localHeaderInterceptor = new LocalHeaderInterceptor(interceptor); interceptors.add(localHeaderInterceptor); channelBuilder.intercept(localHeaderInterceptor).userAgent(interceptor.getUserAgentHeader()); } return GrpcTransportChannel.newBuilder().setManagedChannel(channelBuilder.build()).build(); }