- 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 class
GrpcServiceClient.Builder
Builder to build an instance ofGrpcServiceClient
.static class
GrpcServiceClient.SingleValueStreamObserver<T>
A simpleStreamObserver
adapter class that completes aCompletableFuture
when 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.Builder
builder(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 GrpcServiceClient
create(io.grpc.Channel channel, ClientServiceDescriptor descriptor)
Creates aGrpcServiceClient
.<T> T
proxy(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.String
serviceName()
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
- theChannel
to use to connect to the serverdescriptor
- theClientServiceDescriptor
describing 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
- theChannel
to use to connect to the serverdescriptor
- theClientServiceDescriptor
describing 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
CompletionStage
that 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
- aStreamObserver
to 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
Iterator
to 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
- aStreamObserver
to 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
- anIterable
of items to be streamed to the server- Returns:
- A
StreamObserver
to 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
- aStream
of items to be streamed to the server- Returns:
- A
StreamObserver
to 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
- aStreamObserver
to receive the result- Returns:
- a
StreamObserver
to 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
- aStreamObserver
to receive the result- Returns:
- A
StreamObserver
to use to stream requests to the server
-
-