Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Message a = Message {
- body :: ByteString
- value :: a
- publish :: (RequireRoute a, ToJSON msg, MonadIO m) => Connection -> Key a msg -> msg -> m ()
- publishToExchange :: (RequireRoute a, ToJSON msg, MonadIO m) => Connection -> Key a msg -> msg -> m ()
- takeMessage :: (MonadIO m, FromJSON a) => Connection -> Queue a -> m (Message a)
- worker :: (FromJSON a, MonadIO m) => Connection -> Queue a -> (Message a -> m ()) -> m ()
- consumeNext :: (FromJSON msg, MonadIO m) => Microseconds -> Connection -> Queue msg -> m (ConsumeResult msg)
- consume :: (FromJSON msg, MonadIO m) => Connection -> Queue msg -> m (Maybe (ConsumeResult msg))
- data ConsumeResult a
- = Parsed (Message a)
- | Error ParseError
- data ParseError = ParseError String ByteString
- type Microseconds = Int
Documentation
a parsed message from the queue
Message | |
|
publish :: (RequireRoute a, ToJSON msg, MonadIO m) => Connection -> Key a msg -> msg -> m () Source #
send a message to a queue. Enforces that the message type and queue name are correct at the type level
let newUsers = key "users" & word "new" :: Key Route User publish conn newUsers (User "username")
Publishing to a Binding Key results in an error
-- Compiler error! This doesn't make sense let users = key "users" & many :: Key Binding User publish conn users (User "username")
publishToExchange :: (RequireRoute a, ToJSON msg, MonadIO m) => Connection -> Key a msg -> msg -> m () Source #
publish a message to a routing key, without making sure a queue exists to handle it
publishToExchange conn key (User "username")
takeMessage :: (MonadIO m, FromJSON a) => Connection -> Queue a -> m (Message a) Source #
Wait until a message is read from the queue. Throws an exception if the incoming message doesn't match the key type
m <- Worker.takeMessage conn queue print (value m)
worker :: (FromJSON a, MonadIO m) => Connection -> Queue a -> (Message a -> m ()) -> m () Source #
Create a worker which loops and handles messages. Throws an exception if the incoming message doesn't match the key type. It is recommended that you catch errors in your handler and allow message parsing errors to crash your program.
Worker.worker conn queue $ \m -> do print (value m)
consumeNext :: (FromJSON msg, MonadIO m) => Microseconds -> Connection -> Queue msg -> m (ConsumeResult msg) Source #
Block while checking for messages every N microseconds. Return once you find one.
res <- consumeNext conn queue case res of (Parsed m) -> print m (Error e) -> putStrLn "could not parse message"
consume :: (FromJSON msg, MonadIO m) => Connection -> Queue msg -> m (Maybe (ConsumeResult msg)) Source #
Check for a message once and attempt to parse it
res <- consume conn queue case res of Just (Parsed m) -> print m Just (Error e) -> putStrLn "could not parse message" Nothing -> putStrLn "No messages on the queue"
data ConsumeResult a Source #
Parsed (Message a) | |
Error ParseError |
data ParseError Source #
Instances
Exception ParseError Source # | |
Defined in Network.AMQP.Worker.Message toException :: ParseError -> SomeException # fromException :: SomeException -> Maybe ParseError # displayException :: ParseError -> String # | |
Show ParseError Source # | |
Defined in Network.AMQP.Worker.Message showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS # |
type Microseconds = Int Source #