Copyright | (c) Paul Berens, 2014 |
---|---|
License | Apache 2.0 |
Maintainer | berens.paul@gmail.com |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
This is a haskell client for the NSQ message queue service.
TODO:
- Start implementing a more through client
- Write some form of tests
- More through docs, the initial docs sucks.
- type MsgId = ByteString
- type Topic = Text
- type Channel = Text
- data Message
- data Command
- data FrameType
- data ErrorType
- data OptionalSetting
- data TLS
- data Compression
- data Identification = Identification {}
- data IdentifyMetadata = IdentifyMetadata {}
- data NSQConnection = NSQConnection {}
- message :: Parser Message
- decode :: ByteString -> Maybe Message
- encode :: Command -> ByteString
- defaultIdentify :: Text -> Text -> IdentifyMetadata
- defaultUserAgent :: Text
- encodeMetadata :: IdentifyMetadata -> ByteString
- defaultConfig :: String -> IO NSQConnection
- establish :: NSQConnection -> TQueue Message -> TQueue Command -> IO ()
Documentation
type MsgId = ByteString Source
Message Id, it is a 16-byte hexdecimal string encoded as ASCII
The message and replies back from the server.
OK | Everything is allright. |
Heartbeat | |
CloseWait | Server has closed the connection. |
Error ErrorType | The server sent back an error. |
Message Int64 Word16 MsgId ByteString | A message to be processed. The values are: Nanosecond Timestamp, number of attempts, Message Id, and the content of the message to be processed. |
CatchAllMessage FrameType ByteString | Catch-all message for future expansion. This currently includes the reply from |
NSQ Command
Protocol | The protocol version |
NOP | No-op, usually used in reply to a |
Identify IdentifyMetadata | Client Identification + possible features negotiation. |
Sub Topic Channel Bool | Subscribe to a specified 'Topic'/'Channel', use |
Pub Topic ByteString | Publish a message to the specified |
MPub Topic [ByteString] | Publish multiple messages to a specified |
Rdy Word64 | Update |
Fin MsgId | Finish a message. |
Req MsgId Word64 | Re-queue a message (failure to process), Timeout is in milliseconds. |
Touch MsgId | Reset the timeout for an in-flight message. |
Cls | Cleanly close the connection to the NSQ daemon. |
Command ByteString | Catch-all command for future expansion/custom commands. |
Frame Type of the incoming data from the NSQ daemon.
Types of error that the server can return in response to an Command
Invalid | Something went wrong with the command (IDENTIFY, SUB, PUB, MPUB, RDY, FIN, REQ, TOUCH, CLS) |
BadBody | Bad Body (IDENTIFY, MPUB) |
BadTopic | Bad Topic (most likely used disallowed characters) (SUB, PUB, MPUB) |
BadChannel | Bad channel (Like |
BadMessage | Bad Message (PUB, MPUB) |
PubFailed | Publishing a message failed (PUB) |
MPubFailed | Same as |
FinFailed | Finish failed (Probably already finished or non-existant message-id) (FIN) |
ReqFailed | Requeue failed (REQ) |
TouchFailed | Touch failed (TOUCH) |
Unknown ByteString | New unknown type of error (ANY) |
data OptionalSetting Source
Optional settings, if Disabled
then this setting will be put in the
json as disabled specifically vs "not being listed".
data Compression Source
For Deflate
its the compression level from 0-9
data Identification Source
The client identification
Identification | |
|
data IdentifyMetadata Source
Metadata for feature negotiation, if any of the values
are set it will be sent to the server otherwise they will be omitted.
If the setting is set to Nothing
it will not be sent to the server,
and if its set to Just
Disabled
it will be sent to the server as
disabled explicitly.
IdentifyMetadata | |
|
data NSQConnection Source
Per Connection configuration such as: per nsqd state (rdy, load balance), per topic state (channel)
NSQConnection | |
|
encode :: Command -> ByteString Source
defaultIdentify :: Text -> Text -> IdentifyMetadata Source
Build a default IdentifyMetadata
that makes sense which is
basically just setting the client Identification
and leaving
the rest of the settings up to the server to determine.
defaultUserAgent :: Text Source
The default user agent to send, for identifying what client library is connecting to the nsqd.
encodeMetadata :: IdentifyMetadata -> ByteString Source
Encode the metadata from IdentifyMetadata
into a ByteString
for
feeding the Identify
Command
for sending the metadata to the nsq
daemon as part of the feature negotiation.
defaultConfig :: String -> IO NSQConnection Source
Attempt to come up with an intelligent default NSQConnection
default
by discovering your client's hostname and reusing it for the client id
for the IdentifyMetadata
establish :: NSQConnection -> TQueue Message -> TQueue Command -> IO () Source
Establish a session with the specified nsqd using the provided
TQueue
so that the actual data processing can be done in a decoupled
manner from the hsnsq stack.
This supports connecting to a specific nsqd, it is however recommended in the future when the feature comes out to user a higher layer that handles the load balancing between multiple nsqd.