mirror of https://github.com/grpc/grpc-java.git
Use stub call options for compression
This commit is contained in:
parent
f80ca40fb9
commit
399be9ac73
|
|
@ -31,13 +31,8 @@
|
||||||
|
|
||||||
package io.grpc.examples.experimental;
|
package io.grpc.examples.experimental;
|
||||||
|
|
||||||
import io.grpc.CallOptions;
|
|
||||||
import io.grpc.Channel;
|
|
||||||
import io.grpc.ClientCall;
|
|
||||||
import io.grpc.ClientInterceptor;
|
|
||||||
import io.grpc.Codec;
|
import io.grpc.Codec;
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.ManagedChannel;
|
||||||
import io.grpc.MethodDescriptor;
|
|
||||||
import io.grpc.examples.helloworld.GreeterGrpc;
|
import io.grpc.examples.helloworld.GreeterGrpc;
|
||||||
import io.grpc.examples.helloworld.HelloRequest;
|
import io.grpc.examples.helloworld.HelloRequest;
|
||||||
import io.grpc.examples.helloworld.HelloResponse;
|
import io.grpc.examples.helloworld.HelloResponse;
|
||||||
|
|
@ -66,16 +61,8 @@ public class CompressingHelloWorldClient {
|
||||||
public CompressingHelloWorldClient(String host, int port) {
|
public CompressingHelloWorldClient(String host, int port) {
|
||||||
channel =
|
channel =
|
||||||
NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT)
|
NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT)
|
||||||
.intercept(new ClientInterceptor() {
|
|
||||||
@Override
|
|
||||||
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> interceptCall(
|
|
||||||
MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions,
|
|
||||||
Channel next) {
|
|
||||||
return next.newCall(method, callOptions.withCompressor(new Codec.Gzip()));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
.build();
|
||||||
blockingStub = GreeterGrpc.newBlockingStub(channel);
|
blockingStub = GreeterGrpc.newBlockingStub(channel).withCompressor(new Codec.Gzip());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws InterruptedException {
|
public void shutdown() throws InterruptedException {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ import io.grpc.CallOptions;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ClientInterceptor;
|
import io.grpc.ClientInterceptor;
|
||||||
import io.grpc.ClientInterceptors;
|
import io.grpc.ClientInterceptors;
|
||||||
|
import io.grpc.Compressor;
|
||||||
|
import io.grpc.ExperimentalApi;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
@ -123,6 +125,14 @@ public abstract class AbstractStub<S extends AbstractStub<?>> {
|
||||||
return build(newChannel, callOptions);
|
return build(newChannel, callOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new stub that uses the given compressor.
|
||||||
|
*/
|
||||||
|
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/492")
|
||||||
|
public final S withCompressor(Compressor c) {
|
||||||
|
return build(channel, callOptions.withCompressor(c));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new stub that has the given interceptors attached to the underlying channel.
|
* Returns a new stub that has the given interceptors attached to the underlying channel.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue