| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Client
Description
High-level client implementation for NATS.
Synopsis
- newClient :: [(String, Int)] -> [ConfigOption] -> IO Client
- type ConfigOption = CallOption Config
- withConnectName :: ByteString -> ConfigOption
- withEcho :: Bool -> ConfigOption
- withAuthToken :: AuthTokenData -> ConfigOption
- withUserPass :: UserPassData -> ConfigOption
- withNKey :: NKeyData -> ConfigOption
- withJWT :: JWTTokenData -> ConfigOption
- withTLSCert :: TLSCertData -> ConfigOption
- withMinimumLogLevel :: LogLevel -> ConfigOption
- withLogAction :: (LogEntry -> IO ()) -> ConfigOption
- withConnectionAttempts :: Int -> ConfigOption
- withCallbackConcurrency :: Int -> ConfigOption
- withBufferLimit :: Int -> ConfigOption
- withExitAction :: (ClientExitReason -> IO ()) -> ConfigOption
- data LogLevel
- data LogEntry = LogEntry {}
- renderLogEntry :: LogEntry -> String
- type AuthTokenData = ByteString
- type UserPassData = (User, Pass)
- type NKeyData = ByteString
- type JWTTokenData = ByteString
- type TLSPublicKey = ByteString
- type TLSPrivateKey = ByteString
- type TLSCertData = (TLSPublicKey, TLSPrivateKey)
- data ClientExitReason
Documentation
newClient :: [(String, Int)] -> [ConfigOption] -> IO Client #
newClient creates a new client with optional overrides to default settings.
Examples:
{-# LANGUAGE OverloadedStrings #-}
servers = [("127.0.0.1", 4222)]
configOptions = [withConnectName "example-client"]
client <- newClient servers configOptions
type ConfigOption = CallOption Config #
withConnectName :: ByteString -> ConfigOption #
withConnectName sets the client name sent in CONNECT. Default: no CONNECT name is sent.
Examples:
{-# LANGUAGE OverloadedStrings #-}
client <- newClient [("127.0.0.1", 4222)] [withConnectName "example-client"]
withEcho :: Bool -> ConfigOption #
withEcho configures whether the server echoes messages from this connection. Default: True (messages sent by this client are echoed back).
withAuthToken :: AuthTokenData -> ConfigOption #
withAuthToken configures token authentication. Default: no authentication is configured.
Examples:
{-# LANGUAGE OverloadedStrings #-}
client <- newClient [("127.0.0.1", 4222)] [withAuthToken "s3cr3t"]
withUserPass :: UserPassData -> ConfigOption #
withUserPass configures user/password authentication. Default: no authentication is configured.
Examples:
{-# LANGUAGE OverloadedStrings #-}
client <- newClient [("127.0.0.1", 4222)] [withUserPass ("alice", "secret")]
withNKey :: NKeyData -> ConfigOption #
withNKey configures NKey authentication. Default: no authentication is configured.
Examples:
{-# LANGUAGE OverloadedStrings #-}
client <- newClient [("127.0.0.1", 4222)] [withNKey "SU..."]
withJWT :: JWTTokenData -> ConfigOption #
withJWT configures JWT authentication. Default: no authentication is configured.
Examples:
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as BS
creds <- BS.readFile "user.creds"
client <- newClient [("127.0.0.1", 4222)] [withJWT creds]
withTLSCert :: TLSCertData -> ConfigOption #
withTLSCert configures client TLS credentials. Default: no TLS credentials are configured.
Examples:
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as BS
certPem <- BS.readFile "client.pem"
keyPem <- BS.readFile "client.key"
client <- newClient [("127.0.0.1", 4222)] [withTLSCert (certPem, keyPem)]
withMinimumLogLevel :: LogLevel -> ConfigOption #
withMinimumLogLevel sets the minimum level that will be emitted by the default logger.
Default: Info.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withMinimumLogLevel Info]
withLogAction :: (LogEntry -> IO ()) -> ConfigOption #
withLogAction replaces the default log sink.
Default: logs are rendered with renderLogEntry and written with putStrLn.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withLogAction print]
withConnectionAttempts :: Int -> ConfigOption #
withConnectionAttempts sets the number of connection retries. Default: 5.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withConnectionAttempts 10]
withCallbackConcurrency :: Int -> ConfigOption #
withCallbackConcurrency sets the number of worker threads used for callbacks. Default: 1 (callbacks run serially). Values less than 1 are treated as 1.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withCallbackConcurrency 4]
withBufferLimit :: Int -> ConfigOption #
withBufferLimit sets the maximum outbound message size and parser buffer size in bytes. Default: 4096. Values less than 1 are treated as 1.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withBufferLimit 8192]
withExitAction :: (ClientExitReason -> IO ()) -> ConfigOption #
withExitAction runs a callback when the client exits. Default: no-op.
Examples:
client <- newClient [("127.0.0.1", 4222)] [withExitAction print]
Constructors
| LogEntry | |
renderLogEntry :: LogEntry -> String #
type AuthTokenData = ByteString #
type UserPassData = (User, Pass) #
type NKeyData = ByteString #
type JWTTokenData = ByteString #
type TLSPublicKey = ByteString #
type TLSPrivateKey = ByteString #
type TLSCertData = (TLSPublicKey, TLSPrivateKey) #
data ClientExitReason #
Constructors
| ExitClosedByUser | |
| ExitRetriesExhausted (Maybe String) | |
| ExitServerError Err | |
| ExitResetRequested |
Instances
| Show ClientExitReason | |
Defined in Client.LifecycleAPI Methods showsPrec :: Int -> ClientExitReason -> ShowS # show :: ClientExitReason -> String # showList :: [ClientExitReason] -> ShowS # | |
| Eq ClientExitReason | |
Defined in Client.LifecycleAPI Methods (==) :: ClientExitReason -> ClientExitReason -> Bool # (/=) :: ClientExitReason -> ClientExitReason -> Bool # | |