amqp-worker-1.0.0: Type-safe AMQP workers
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.AMQP.Worker.Message

Synopsis

Documentation

data Message a Source #

a parsed message from the queue

Constructors

Message 

Fields

Instances

Instances details
Show a => Show (Message a) Source # 
Instance details

Defined in Network.AMQP.Worker.Message

Methods

showsPrec :: Int -> Message a -> ShowS #

show :: Message a -> String #

showList :: [Message a] -> ShowS #

Eq a => Eq (Message a) Source # 
Instance details

Defined in Network.AMQP.Worker.Message

Methods

(==) :: Message a -> Message a -> Bool #

(/=) :: Message a -> Message a -> Bool #

publishToExchange :: (RequireRouting 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 or if it is the right type of message body

publishToExchange conn key (User "username")

publish :: (RequireRouting 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 key = key "users" :: Key Routing User
publish conn key (User "username")

Publishing to a Binding Key results in an error

-- Compiler error! This doesn't make sense
let key = key "users" & many :: Key Binding User
publish conn key (User "username")

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"

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"