A gRPC server is used to adapt unary, client streaming, server streaming or bidirectional streaming server GrpcExchangeHandler
into HTTP server ExchangeHandler
.
gRPC runs on top of HTTP/2 protocol, it defines four kinds of service method as defined by gRPC core concepts:
- Unary RPCs: for request/response exchanges.
- Client streaming RPCs: for stream/response exchanges.
- Server streaming RPCs: for request/stream exchanges.
- Bidirectional streaming RPCs: for stream/stream exchanges.
The GrpcServer
defines four methods for adapting above RPC methods into an ExchangeHandler
that can then be used as HTTP server handler in a ServerController
or as a Web
route handler. The resulting exchange handler basically converts the HTTP server exchange into a gRPC exchange corresponding to above RPC methods before delegating the processing to the wrapped
gRPC exchange handler.
The handler provided by errorHandler()
can also be used to handle global errors in an HTTP server or a Web server by setting the gRPC error status and message corresponding to the error
into the response.
- Since:
- 1.9
- Author:
- Jeremy Kuhn
-
Method Summary
Modifier and TypeMethodDescription<A extends ExchangeContext,
B extends Exchange<A>, C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.BidirectionalStreaming<A, C, D>>
ExchangeHandler<A, B> bidirectionalStreaming
(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Streaming<C>, GrpcResponse.Streaming<D>, E> grpcExchangeHandler) Adapts the specified bidirectional streaming gRPC exchange handler in an HTTP exchange handler.<A extends ExchangeContext,
B extends Exchange<A>, C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.ClientStreaming<A, C, D>>
ExchangeHandler<A, B> clientStreaming
(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Streaming<C>, GrpcResponse.Unary<D>, E> grpcExchangeHandler) Adapts the specified client streaming gRPC exchange handler in an HTTP exchange handler.<A extends ExchangeContext,
B extends ErrorExchange<A>>
ExchangeHandler<A, B> A global error handler that sets gRPC error status and message.<A extends ExchangeContext,
B extends Exchange<A>, C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.ServerStreaming<A, C, D>>
ExchangeHandler<A, B> serverStreaming
(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Unary<C>, GrpcResponse.Streaming<D>, E> grpcExchangeHandler) Adapts the specified server streaming gRPC exchange handler in an HTTP exchange handler.<A extends ExchangeContext,
B extends Exchange<A>, C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.Unary<A, C, D>>
ExchangeHandler<A, B> unary
(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Unary<C>, GrpcResponse.Unary<D>, E> grpcExchangeHandler) Adapts the specified unary gRPC exchange handler in an HTTP exchange handler.
-
Method Details
-
unary
<A extends ExchangeContext,B extends Exchange<A>, ExchangeHandler<A,C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.Unary<A, C, D>> B> unary(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Unary<C>, GrpcResponse.Unary<D>, E> grpcExchangeHandler) Adapts the specified unary gRPC exchange handler in an HTTP exchange handler.
- Type Parameters:
A
- the exchange context typeB
- the server exchange typeC
- the request typeD
- the response typeE
- the gRPC unary exchange type- Parameters:
defaultRequestInstance
- the default instance of the requestdefaultResponseInstance
- the default instance of the responsegrpcExchangeHandler
- the gRPC exchange handler- Returns:
- an HTTP exchange handler
-
clientStreaming
<A extends ExchangeContext,B extends Exchange<A>, ExchangeHandler<A,C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.ClientStreaming<A, C, D>> B> clientStreaming(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Streaming<C>, GrpcResponse.Unary<D>, E> grpcExchangeHandler) Adapts the specified client streaming gRPC exchange handler in an HTTP exchange handler.
- Type Parameters:
A
- the exchange context typeB
- the server exchange typeC
- the request typeD
- the response typeE
- the gRPC unary exchange type- Parameters:
defaultRequestInstance
- the default instance of the requestdefaultResponseInstance
- the default instance of the responsegrpcExchangeHandler
- the gRPC exchange handler- Returns:
- an HTTP exchange handler
-
serverStreaming
<A extends ExchangeContext,B extends Exchange<A>, ExchangeHandler<A,C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.ServerStreaming<A, C, D>> B> serverStreaming(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Unary<C>, GrpcResponse.Streaming<D>, E> grpcExchangeHandler) Adapts the specified server streaming gRPC exchange handler in an HTTP exchange handler.
- Type Parameters:
A
- the exchange context typeB
- the server exchange typeC
- the request typeD
- the response typeE
- the gRPC unary exchange type- Parameters:
defaultRequestInstance
- the default instance of the requestdefaultResponseInstance
- the default instance of the responsegrpcExchangeHandler
- the gRPC exchange handler- Returns:
- an HTTP exchange handler
-
bidirectionalStreaming
<A extends ExchangeContext,B extends Exchange<A>, ExchangeHandler<A,C extends com.google.protobuf.Message, D extends com.google.protobuf.Message, E extends GrpcExchange.BidirectionalStreaming<A, C, D>> B> bidirectionalStreaming(C defaultRequestInstance, D defaultResponseInstance, GrpcExchangeHandler<A, C, D, GrpcRequest.Streaming<C>, GrpcResponse.Streaming<D>, E> grpcExchangeHandler) Adapts the specified bidirectional streaming gRPC exchange handler in an HTTP exchange handler.
- Type Parameters:
A
- the exchange context typeB
- the server exchange typeC
- the request typeD
- the response typeE
- the gRPC unary exchange type- Parameters:
defaultRequestInstance
- the default instance of the requestdefaultResponseInstance
- the default instance of the responsegrpcExchangeHandler
- the gRPC exchange handler- Returns:
- an HTTP exchange handler
-
errorHandler
A global error handler that sets gRPC error status and message.
This handler is only useful for handling errors that happened outside the normal processing of the gRPC exchange, this is especially the case of internal errors or errors raised in interceptors (e.g. authentication errors, permissions errors...)
- Type Parameters:
A
- the exchange context typeB
- the error exchange type- Returns:
- an error exchange handler
-