Copyright | (c) Help.com, LLC, 2014 |
---|---|
License | MIT |
Maintainer | alex.martin@help.com |
Stability | Stable |
Portability | UNIX |
Safe Haskell | None |
Language | Haskell98 |
- class EsbSend a where
- class EsbRecieve a where
- esbRecieve :: Socket -> a -> IO ()
- class EsbSendExternal a b where
- esbSendExternal :: Socket -> a -> b -> IO ()
- class EsbRecieveExternal a b where
- esbRecieveExternal :: Socket -> a -> b -> IO ()
- getSocket :: String -> Int -> IO Socket
- sendSocketData :: Socket -> ByteString -> IO ()
- readSocketDataRaw :: Socket -> IO [Char]
- readSocketData :: Socket -> IO ByteString
- esbInit :: Text -> [Text] -> Maybe String -> Maybe Int -> IO Socket
- esbListen :: Socket -> IO [ByteString]
- encode :: ToJSON a => a -> ByteString
- decode :: FromJSON a => ByteString -> Maybe a
- eitherDecode :: FromJSON a => ByteString -> Either String a
- logger :: String -> IO ()
- forM_ :: Monad m => [a] -> (a -> m b) -> m ()
- data Socket :: *
- module Data.UUID
- module Data.UUID.V4
- module System.Environment
- module Control.Monad
Classes
The EsbSend
class determines how a message should be sent to the ESB.
The esbSend
method takes a socket and writes some kind of payload.
class EsbRecieve a where Source
The EsbRecieve
class determines how a message from the ESB should be
recieved.
The esbRecieve
method takes a socket and reads some kind of payload.
EsbRecieve Message | The |
class EsbSendExternal a b where Source
The EsbSendExternal
is similar to EsbSend
, just with an option to
involve external resources.
:: Socket | The socket connection. |
-> a | The payload. |
-> b | Another resource to be used, i.e. DB connection, API, etc. |
-> IO () | Any IO output. |
The esbSendExternal
method takes a socket and writes some kind of payload.
class EsbRecieveExternal a b where Source
The EsbRecieveExternal
is similar to EsbRecieve
, just with an option to
involve external resources.
:: Socket | The socket connection. |
-> a | The payload. |
-> b | Another resource to be used, i.e. DB connection, API, etc. |
-> IO () | Any IO output. |
The esbRecieveExternal
method takes a socket and reads some kind of payload.
Raw Exported Functions
The getSocket
function takes a host and port and connects to and
returns the socket.
:: Socket | The socket connection. |
-> ByteString | The JSON bytestring payload. |
-> IO () | Any IO output. |
The sendSocketData
function accepts a socket and bytes, converts the
bytes to cleaned up JSON, and writes the JSON to the socket.
The readSocketDataRaw
function accepts a socket and grabs whatever
data might be in the latest message.
:: Socket | The socket connection. |
-> IO ByteString | The JSON bytestring payload. |
The readSocketData
function accepts a socket, reads and cleans up
any JSON for parsing, and returns the bytes of JSON.
ESB Functions
:: Text | Group name. |
-> [Text] | Subscriptions. |
-> Maybe String | Host address or Nothing. Defaults to 127.0.0.1. |
-> Maybe Int | Host port or Nothing. Defaults to 8900. |
-> IO Socket | The socket connection. |
The esbInit
function initializes the socket connection and logs
into the ESB.
:: Socket | The socket connection. |
-> IO [ByteString] | The array of JSON bytestring payload. |
The esbListen
function performs all essential listening logic
for any ESB client.
Utility Functions
encode :: ToJSON a => a -> ByteString
Efficiently serialize a JSON value as a lazy ByteString
.
decode :: FromJSON a => ByteString -> Maybe a
Efficiently deserialize a JSON value from a lazy ByteString
.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace. This restriction is necessary to ensure that if data is being lazily read from a file handle, the file handle will be closed in a timely fashion once the document has been parsed.
This function parses immediately, but defers conversion. See
json
for details.
eitherDecode :: FromJSON a => ByteString -> Either String a
Like decode
but returns an error message when decoding fails.
The logger
function simply logs out in a consistent way. Will be
updated to be more robust.
Utility Types
module Data.UUID
module Data.UUID.V4
module System.Environment
module Control.Monad