natskell
Safe HaskellNone
LanguageHaskell2010

Client

Description

High-level client implementation for NATS.

Synopsis

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]

data LogLevel #

Constructors

Debug 
Info 
Warn 
Error 
Fatal 

Instances

Instances details
Show LogLevel 
Instance details

Defined in Lib.Logger.Types

Eq LogLevel 
Instance details

Defined in Lib.Logger.Types

Ord LogLevel 
Instance details

Defined in Lib.Logger.Types

data LogEntry #

Instances

Instances details
Show LogEntry 
Instance details

Defined in Lib.Logger.Types

Eq LogEntry 
Instance details

Defined in Lib.Logger.Types

type UserPassData = (User, Pass) #