Safe Haskell | None |
---|---|
Language | Haskell2010 |
Set of helpers helping with writing gRPC clients with not much exposure of the http2-client complexity.
The GrpcClient handles automatic background connection-level window updates to prevent the connection from starving and pings to force a connection alive.
There is no automatic reconnection, retry, or healthchecking. These features are not planned in this library and should be added at higher-levels.
Synopsis
- data GrpcClient = GrpcClient {}
- data BackgroundTasks = BackgroundTasks {
- backgroundWindowUpdate :: Async (Either ClientError ())
- backgroundPing :: Async (Either ClientError ())
- data GrpcClientConfig = GrpcClientConfig {
- _grpcClientConfigHost :: !HostName
- _grpcClientConfigPort :: !PortNumber
- _grpcClientConfigHeaders :: ![(ByteString, ByteString)]
- _grpcClientConfigTimeout :: !Timeout
- _grpcClientConfigCompression :: !Compression
- _grpcClientConfigTLS :: !(Maybe ClientParams)
- _grpcClientConfigGoAwayHandler :: GoAwayHandler
- _grpcClientConfigFallbackHandler :: FallBackFrameHandler
- _grpcClientConfigWindowUpdateDelay :: Int
- _grpcClientConfigPingDelay :: Int
- grpcClientConfigSimple :: HostName -> PortNumber -> UseTlsOrNot -> GrpcClientConfig
- type UseTlsOrNot = Bool
- tlsSettings :: UseTlsOrNot -> HostName -> PortNumber -> Maybe ClientParams
- setupGrpcClient :: GrpcClientConfig -> ClientIO GrpcClient
- close :: GrpcClient -> ClientIO ()
- rawUnary :: (GRPCInput r i, GRPCOutput r o) => r -> GrpcClient -> i -> ClientIO (Either TooMuchConcurrency (RawReply o))
- rawStreamServer :: (GRPCInput r i, GRPCOutput r o) => r -> GrpcClient -> a -> i -> (a -> HeaderList -> o -> ClientIO a) -> ClientIO (Either TooMuchConcurrency (a, HeaderList, HeaderList))
- rawStreamClient :: (GRPCInput r i, GRPCOutput r o) => r -> GrpcClient -> a -> (a -> ClientIO (a, Either StreamDone (CompressMode, i))) -> ClientIO (Either TooMuchConcurrency (a, RawReply o))
- rawSteppedBidirectional :: (GRPCInput r i, GRPCOutput r o) => r -> GrpcClient -> a -> RunBiDiStep i o a -> ClientIO (Either TooMuchConcurrency a)
- rawGeneralStream :: (GRPCInput r i, GRPCOutput r o) => r -> GrpcClient -> a -> (a -> IncomingEvent o a -> ClientIO a) -> b -> (b -> ClientIO (b, OutgoingEvent i b)) -> ClientIO (Either TooMuchConcurrency (a, b))
Documentation
data GrpcClient Source #
A simplified gRPC Client connected via an HTTP2Client to a given server. Each call from one client will share similar headers, timeout, compression.
GrpcClient | |
|
data BackgroundTasks Source #
BackgroundTasks | |
|
data GrpcClientConfig Source #
Configuration to setup a GrpcClient.
GrpcClientConfig | |
|
type UseTlsOrNot = Bool Source #
tlsSettings :: UseTlsOrNot -> HostName -> PortNumber -> Maybe ClientParams Source #
close :: GrpcClient -> ClientIO () Source #
Cancels background tasks and closes the underlying HTTP2 client.
:: (GRPCInput r i, GRPCOutput r o) | |
=> r | The RPC to call. |
-> GrpcClient | An initialized client. |
-> i | The input. |
-> ClientIO (Either TooMuchConcurrency (RawReply o)) |
Run an unary query.
:: (GRPCInput r i, GRPCOutput r o) | |
=> r | The RPC to call. |
-> GrpcClient | An initialized client. |
-> a | An initial state. |
-> i | The input of the stream request. |
-> (a -> HeaderList -> o -> ClientIO a) | A state-passing handler called for each server-sent output. Headers are repeated for convenience but are the same for every iteration. |
-> ClientIO (Either TooMuchConcurrency (a, HeaderList, HeaderList)) |
Calls for a server stream of requests.
:: (GRPCInput r i, GRPCOutput r o) | |
=> r | The RPC to call. |
-> GrpcClient | An initialized client. |
-> a | An initial state. |
-> (a -> ClientIO (a, Either StreamDone (CompressMode, i))) | A state-passing step function to decide the next message. |
-> ClientIO (Either TooMuchConcurrency (a, RawReply o)) |
Sends a streams of requests to the server.
Messages are submitted to the HTTP2 underlying client and hence this function can block until the HTTP2 client has some network credit.
rawSteppedBidirectional Source #
:: (GRPCInput r i, GRPCOutput r o) | |
=> r | The RPC to call. |
-> GrpcClient | An initialized client. |
-> a | An initial state. |
-> RunBiDiStep i o a | The sequential program to iterate between sending and receiving messages. |
-> ClientIO (Either TooMuchConcurrency a) |
Starts a bidirectional ping-pong like stream with the server.
This handler is well-suited when the gRPC application has a deterministic protocols, that is, when after sending a message a client can know how many messages to wait for before sending the next message.
:: (GRPCInput r i, GRPCOutput r o) | |
=> r | The RPC to call. |
-> GrpcClient | An initialized client. |
-> a | An initial state for the incoming loop. |
-> (a -> IncomingEvent o a -> ClientIO a) | A state-passing function for the incoming loop. |
-> b | An initial state for the outgoing loop. |
-> (b -> ClientIO (b, OutgoingEvent i b)) | A state-passing function for the ougoing loop. |
-> ClientIO (Either TooMuchConcurrency (a, b)) |
Starts a stream with the server.
This handler allows to concurrently write messages and wait for incoming messages.