| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
API
Description
Capability record for the NATS client surface.
Synopsis
- data Client = Client {
- publish :: Subject -> [PublishOption] -> IO ()
- subscribe :: Subject -> [SubscribeOption] -> (Maybe MsgView -> IO ()) -> IO SID
- request :: Subject -> [SubscribeOption] -> (Maybe MsgView -> IO ()) -> IO SID
- unsubscribe :: SID -> IO ()
- newInbox :: IO Subject
- ping :: IO () -> IO ()
- flush :: IO ()
- reset :: IO ()
- close :: IO ()
- data MsgView = MsgView {
- subject :: ByteString
- sid :: ByteString
- replyTo :: Maybe ByteString
- payload :: Maybe ByteString
- headers :: Maybe [(ByteString, ByteString)]
- type PublishOption = CallOption PublishConfig
- type SubscribeOption = CallOption SubscribeConfig
- withSubscriptionExpiry :: NominalDiffTime -> SubscribeOption
- withQueueGroup :: Subject -> SubscribeOption
- withPayload :: Payload -> PublishOption
- withReplyCallback :: (Maybe MsgView -> IO ()) -> PublishOption
- withReplyTo :: Subject -> PublishOption
- withHeaders :: Headers -> PublishOption
Documentation
Client capabilities for publishing, subscribing, and lifecycle control.
Constructors
| Client | |
Fields
| |
MsgView represents a MSG in the NATS protocol.
Constructors
| MsgView | |
Fields
| |
type PublishOption = CallOption PublishConfig Source #
type SubscribeOption = CallOption SubscribeConfig Source #
withSubscriptionExpiry :: NominalDiffTime -> SubscribeOption Source #
withSubscriptionExpiry sets the reply subscription expiry in seconds. Default: no expiry (reply subscriptions stay open until unsubscribe).
Examples:
{-# LANGUAGE OverloadedStrings #-}
subscribe client "events.created" [withSubscriptionExpiry 2] print
withQueueGroup :: Subject -> SubscribeOption Source #
withQueueGroup sets the queue group for a subscription. Default: no queue group.
withPayload :: Payload -> PublishOption Source #
withPayload is used to set the payload for a publish operation. Default: no payload.
Examples:
{-# LANGUAGE OverloadedStrings #-}
publish client "updates" [withPayload "hello"]
withReplyCallback :: (Maybe MsgView -> IO ()) -> PublishOption Source #
withReplyCallback is used to set a callback for a reply to a publish operation. Default: no reply subscription; publishes are fire-and-forget.
Examples:
{-# LANGUAGE OverloadedStrings #-}
publish client "service.echo" [withReplyCallback print]
withReplyTo :: Subject -> PublishOption Source #
withReplyTo sets an explicit reply subject for a publish operation. Default: no reply subject unless a reply callback is configured.
This option only controls the outgoing reply subject. It does not create a subscription; callers that expect multiple replies should subscribe to the reply subject themselves.
withHeaders :: Headers -> PublishOption Source #
withHeaders is used to set headers for a publish operation. Default: no headers.
Examples:
{-# LANGUAGE OverloadedStrings #-}
publish client "updates" [withHeaders [("source", "test")]]