- java.lang.Object
-
- io.helidon.grpc.client.GrpcServiceClient
-
public class GrpcServiceClient extends Object
A gRPC Client for a specific gRPC service.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGrpcServiceClient.BuilderBuilder to build an instance ofGrpcServiceClient.static classGrpcServiceClient.SingleValueStreamObserver<T>A simpleStreamObserveradapter class that completes aCompletableFuturewhen the observer is completed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <ReqT,RespT>
io.grpc.stub.StreamObserver<ReqT>bidiStreaming(String methodName, io.grpc.stub.StreamObserver<RespT> observer)Invoke the specified bidirectional streaming method.<ReqT,RespT>
Iterator<RespT>blockingServerStreaming(String methodName, ReqT request)Invoke the specified server streaming method.<ReqT,RespT>
RespTblockingUnary(String methodName, ReqT request)Invoke the specified unary method with the specified request object.static GrpcServiceClient.Builderbuilder(io.grpc.Channel channel, ClientServiceDescriptor descriptor)Creates aGrpcServiceClient.Builder.<ReqT,RespT>
io.grpc.stub.StreamObserver<ReqT>clientStreaming(String methodName, io.grpc.stub.StreamObserver<RespT> observer)Invoke the specified client streaming method.<ReqT,RespT>
CompletionStage<RespT>clientStreaming(String methodName, Iterable<ReqT> items)Invoke the specified client streaming method.<ReqT,RespT>
CompletionStage<RespT>clientStreaming(String methodName, Stream<ReqT> items)Invoke the specified client streaming method.static GrpcServiceClientcreate(io.grpc.Channel channel, ClientServiceDescriptor descriptor)Creates aGrpcServiceClient.<T> Tproxy(Class<T> type, Class<?>... extraTypes)Create a dynamic proxy for the specified interface that proxies calls to the wrapped gRPC service.<ReqT,RespT>
voidserverStreaming(String methodName, ReqT request, io.grpc.stub.StreamObserver<RespT> observer)Invoke the specified server streaming method.StringserviceName()Obtain the service name.<ReqT,RespT>
CompletionStage<RespT>unary(String methodName, ReqT request)Asynchronously invoke the specified unary method.<ReqT,RespT>
voidunary(String methodName, ReqT request, io.grpc.stub.StreamObserver<RespT> observer)Invoke the specified unary method.
-
-
-
Method Detail
-
builder
public static GrpcServiceClient.Builder builder(io.grpc.Channel channel, ClientServiceDescriptor descriptor)
Creates aGrpcServiceClient.Builder.- Parameters:
channel- theChannelto use to connect to the serverdescriptor- theClientServiceDescriptordescribing the gRPC service- Returns:
- a new instance of
GrpcServiceClient.Builder
-
create
public static GrpcServiceClient create(io.grpc.Channel channel, ClientServiceDescriptor descriptor)
Creates aGrpcServiceClient.- Parameters:
channel- theChannelto use to connect to the serverdescriptor- theClientServiceDescriptordescribing the gRPC service- Returns:
- a new instance of
GrpcServiceClient.Builder
-
serviceName
public String serviceName()
Obtain the service name.- Returns:
- The name of the service
-
proxy
public <T> T proxy(Class<T> type, Class<?>... extraTypes)
Create a dynamic proxy for the specified interface that proxies calls to the wrapped gRPC service.- Type Parameters:
T- the type of the returned proxy- Parameters:
type- the interface to create a proxy forextraTypes- extra types for the proxy to implement- Returns:
- a dynamic proxy that calls methods on this gRPC service
-
blockingUnary
public <ReqT,RespT> RespT blockingUnary(String methodName, ReqT request)
Invoke the specified unary method with the specified request object.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedrequest- the request parameter- Returns:
- The result of this invocation
-
unary
public <ReqT,RespT> CompletionStage<RespT> unary(String methodName, ReqT request)
Asynchronously invoke the specified unary method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedrequest- the request parameter- Returns:
- A
CompletionStagethat will complete with the result of the unary method call
-
unary
public <ReqT,RespT> void unary(String methodName, ReqT request, io.grpc.stub.StreamObserver<RespT> observer)
Invoke the specified unary method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedrequest- the request parameterobserver- aStreamObserverto receive the result
-
blockingServerStreaming
public <ReqT,RespT> Iterator<RespT> blockingServerStreaming(String methodName, ReqT request)
Invoke the specified server streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedrequest- the request parameter- Returns:
- an
Iteratorto obtain the streamed results
-
serverStreaming
public <ReqT,RespT> void serverStreaming(String methodName, ReqT request, io.grpc.stub.StreamObserver<RespT> observer)
Invoke the specified server streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedrequest- the request parameterobserver- aStreamObserverto receive the results
-
clientStreaming
public <ReqT,RespT> CompletionStage<RespT> clientStreaming(String methodName, Iterable<ReqT> items)
Invoke the specified client streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokeditems- anIterableof items to be streamed to the server- Returns:
- A
StreamObserverto retrieve the method call result
-
clientStreaming
public <ReqT,RespT> CompletionStage<RespT> clientStreaming(String methodName, Stream<ReqT> items)
Invoke the specified client streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokeditems- aStreamof items to be streamed to the server- Returns:
- A
StreamObserverto retrieve the method call result
-
clientStreaming
public <ReqT,RespT> io.grpc.stub.StreamObserver<ReqT> clientStreaming(String methodName, io.grpc.stub.StreamObserver<RespT> observer)
Invoke the specified client streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invokedobserver- aStreamObserverto receive the result- Returns:
- a
StreamObserverto use to stream requests to the server
-
bidiStreaming
public <ReqT,RespT> io.grpc.stub.StreamObserver<ReqT> bidiStreaming(String methodName, io.grpc.stub.StreamObserver<RespT> observer)
Invoke the specified bidirectional streaming method.- Type Parameters:
ReqT- the request typeRespT- the response type- Parameters:
methodName- the method name to be invoked.observer- aStreamObserverto receive the result- Returns:
- A
StreamObserverto use to stream requests to the server
-
-