{-# LANGUAGE BangPatterns, DeriveDataTypeable, OverloadedStrings, ScopedTypeVariables #-}
module Network.AMQP (
Connection,
ConnectionOpts(..),
TLSSettings(..),
defaultConnectionOpts,
openConnection,
openConnection',
openConnection'',
closeChannel,
closeConnection,
addConnectionClosedHandler,
addConnectionBlockedHandler,
getServerProperties,
Channel,
openChannel,
addReturnListener,
addChannelExceptionHandler,
isNormalChannelClose,
qos,
ExchangeOpts(..),
newExchange,
declareExchange,
bindExchange,
bindExchange',
unbindExchange,
unbindExchange',
deleteExchange,
QueueOpts(..),
newQueue,
declareQueue,
bindQueue,
bindQueue',
unbindQueue,
unbindQueue',
purgeQueue,
deleteQueue,
Message(..),
DeliveryMode(..),
PublishError(..),
ReturnReplyCode(..),
newMsg,
Envelope(..),
ConsumerTag,
Ack(..),
consumeMsgs,
consumeMsgs',
cancelConsumer,
publishMsg,
publishMsg',
getMsg,
rejectMsg,
rejectEnv,
recoverMsgs,
ackMsg,
ackEnv,
nackMsg,
nackEnv,
txSelect,
txCommit,
txRollback,
confirmSelect,
waitForConfirms,
waitForConfirmsUntil,
addConfirmationListener,
ConfirmationResult(..),
AckType(..),
flow,
SASLMechanism(..),
plain,
amqplain,
rabbitCRdemo,
AMQPException(..),
ChanThreadKilledException,
CloseType(..),
fromURI
) where
import Control.Applicative
import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad(when)
import Data.List.Split (splitOn)
import Data.Binary
import Data.Binary.Put
import Network.Socket (PortNumber)
import Network.URI (unEscapeString)
import Data.Text (Text)
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString as BS
import qualified Data.IntSet as IntSet
import qualified Data.Text.Encoding as E
import qualified Data.Map as M
import qualified Data.Text as T
import Network.AMQP.Types
import Network.AMQP.Generated
import Network.AMQP.Internal
import Network.AMQP.Helpers
data ExchangeOpts = ExchangeOpts {
ExchangeOpts -> Text
exchangeName :: Text,
ExchangeOpts -> Text
exchangeType :: Text,
ExchangeOpts -> Bool
exchangePassive :: Bool,
ExchangeOpts -> Bool
exchangeDurable :: Bool,
ExchangeOpts -> Bool
exchangeAutoDelete :: Bool,
ExchangeOpts -> Bool
exchangeInternal :: Bool,
ExchangeOpts -> FieldTable
exchangeArguments :: FieldTable
} deriving (ExchangeOpts -> ExchangeOpts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExchangeOpts -> ExchangeOpts -> Bool
$c/= :: ExchangeOpts -> ExchangeOpts -> Bool
== :: ExchangeOpts -> ExchangeOpts -> Bool
$c== :: ExchangeOpts -> ExchangeOpts -> Bool
Eq, Eq ExchangeOpts
ExchangeOpts -> ExchangeOpts -> Bool
ExchangeOpts -> ExchangeOpts -> Ordering
ExchangeOpts -> ExchangeOpts -> ExchangeOpts
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ExchangeOpts -> ExchangeOpts -> ExchangeOpts
$cmin :: ExchangeOpts -> ExchangeOpts -> ExchangeOpts
max :: ExchangeOpts -> ExchangeOpts -> ExchangeOpts
$cmax :: ExchangeOpts -> ExchangeOpts -> ExchangeOpts
>= :: ExchangeOpts -> ExchangeOpts -> Bool
$c>= :: ExchangeOpts -> ExchangeOpts -> Bool
> :: ExchangeOpts -> ExchangeOpts -> Bool
$c> :: ExchangeOpts -> ExchangeOpts -> Bool
<= :: ExchangeOpts -> ExchangeOpts -> Bool
$c<= :: ExchangeOpts -> ExchangeOpts -> Bool
< :: ExchangeOpts -> ExchangeOpts -> Bool
$c< :: ExchangeOpts -> ExchangeOpts -> Bool
compare :: ExchangeOpts -> ExchangeOpts -> Ordering
$ccompare :: ExchangeOpts -> ExchangeOpts -> Ordering
Ord, ReadPrec [ExchangeOpts]
ReadPrec ExchangeOpts
Int -> ReadS ExchangeOpts
ReadS [ExchangeOpts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExchangeOpts]
$creadListPrec :: ReadPrec [ExchangeOpts]
readPrec :: ReadPrec ExchangeOpts
$creadPrec :: ReadPrec ExchangeOpts
readList :: ReadS [ExchangeOpts]
$creadList :: ReadS [ExchangeOpts]
readsPrec :: Int -> ReadS ExchangeOpts
$creadsPrec :: Int -> ReadS ExchangeOpts
Read, Int -> ExchangeOpts -> ShowS
[ExchangeOpts] -> ShowS
ExchangeOpts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExchangeOpts] -> ShowS
$cshowList :: [ExchangeOpts] -> ShowS
show :: ExchangeOpts -> String
$cshow :: ExchangeOpts -> String
showsPrec :: Int -> ExchangeOpts -> ShowS
$cshowsPrec :: Int -> ExchangeOpts -> ShowS
Show)
newExchange :: ExchangeOpts
newExchange :: ExchangeOpts
newExchange = Text
-> Text
-> Bool
-> Bool
-> Bool
-> Bool
-> FieldTable
-> ExchangeOpts
ExchangeOpts Text
"" Text
"" Bool
False Bool
True Bool
False Bool
False (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
declareExchange :: Channel -> ExchangeOpts -> IO ()
declareExchange :: Channel -> ExchangeOpts -> IO ()
declareExchange Channel
chan ExchangeOpts
exchg = do
(SimpleMethod MethodPayload
Exchange_declare_ok) <- Channel -> Assembly -> IO Assembly
request Channel
chan (MethodPayload -> Assembly
SimpleMethod (ShortInt
-> ShortString
-> ShortString
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> FieldTable
-> MethodPayload
Exchange_declare
ShortInt
1
(Text -> ShortString
ShortString forall a b. (a -> b) -> a -> b
$ ExchangeOpts -> Text
exchangeName ExchangeOpts
exchg)
(Text -> ShortString
ShortString forall a b. (a -> b) -> a -> b
$ ExchangeOpts -> Text
exchangeType ExchangeOpts
exchg)
(ExchangeOpts -> Bool
exchangePassive ExchangeOpts
exchg)
(ExchangeOpts -> Bool
exchangeDurable ExchangeOpts
exchg)
(ExchangeOpts -> Bool
exchangeAutoDelete ExchangeOpts
exchg)
(ExchangeOpts -> Bool
exchangeInternal ExchangeOpts
exchg)
Bool
False
(ExchangeOpts -> FieldTable
exchangeArguments ExchangeOpts
exchg)))
forall (m :: * -> *) a. Monad m => a -> m a
return ()
bindExchange :: Channel -> Text -> Text -> Text -> IO ()
bindExchange :: Channel -> Text -> Text -> Text -> IO ()
bindExchange Channel
chan Text
destinationName Text
sourceName Text
routingKey =
Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindExchange' Channel
chan Text
destinationName Text
sourceName Text
routingKey (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
bindExchange' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindExchange' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindExchange' Channel
chan Text
destinationName Text
sourceName Text
routingKey FieldTable
args = do
(SimpleMethod MethodPayload
Exchange_bind_ok) <- Channel -> Assembly -> IO Assembly
request Channel
chan (MethodPayload -> Assembly
SimpleMethod (ShortInt
-> ShortString
-> ShortString
-> ShortString
-> Bool
-> FieldTable
-> MethodPayload
Exchange_bind
ShortInt
1
(Text -> ShortString
ShortString Text
destinationName)
(Text -> ShortString
ShortString Text
sourceName)
(Text -> ShortString
ShortString Text
routingKey)
Bool
False
FieldTable
args
))
forall (m :: * -> *) a. Monad m => a -> m a
return ()
unbindExchange :: Channel -> Text -> Text -> Text -> IO ()
unbindExchange :: Channel -> Text -> Text -> Text -> IO ()
unbindExchange Channel
chan Text
destinationName Text
sourceName Text
routingKey =
Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindExchange' Channel
chan Text
destinationName Text
sourceName Text
routingKey (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
unbindExchange' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindExchange' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindExchange' Channel
chan Text
destinationName Text
sourceName Text
routingKey FieldTable
args = do
SimpleMethod MethodPayload
Exchange_unbind_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt
-> ShortString
-> ShortString
-> ShortString
-> Bool
-> FieldTable
-> MethodPayload
Exchange_unbind
ShortInt
1
(Text -> ShortString
ShortString Text
destinationName)
(Text -> ShortString
ShortString Text
sourceName)
(Text -> ShortString
ShortString Text
routingKey)
Bool
False
FieldTable
args
forall (m :: * -> *) a. Monad m => a -> m a
return ()
deleteExchange :: Channel -> Text -> IO ()
deleteExchange :: Channel -> Text -> IO ()
deleteExchange Channel
chan Text
exchange = do
(SimpleMethod MethodPayload
Exchange_delete_ok) <- Channel -> Assembly -> IO Assembly
request Channel
chan (MethodPayload -> Assembly
SimpleMethod (ShortInt -> ShortString -> Bool -> Bool -> MethodPayload
Exchange_delete
ShortInt
1
(Text -> ShortString
ShortString Text
exchange)
Bool
False
Bool
False
))
forall (m :: * -> *) a. Monad m => a -> m a
return ()
data QueueOpts = QueueOpts {
QueueOpts -> Text
queueName :: Text,
QueueOpts -> Bool
queuePassive :: Bool,
QueueOpts -> Bool
queueDurable :: Bool,
QueueOpts -> Bool
queueExclusive :: Bool,
QueueOpts -> Bool
queueAutoDelete :: Bool,
:: FieldTable
} deriving (QueueOpts -> QueueOpts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueueOpts -> QueueOpts -> Bool
$c/= :: QueueOpts -> QueueOpts -> Bool
== :: QueueOpts -> QueueOpts -> Bool
$c== :: QueueOpts -> QueueOpts -> Bool
Eq, Eq QueueOpts
QueueOpts -> QueueOpts -> Bool
QueueOpts -> QueueOpts -> Ordering
QueueOpts -> QueueOpts -> QueueOpts
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: QueueOpts -> QueueOpts -> QueueOpts
$cmin :: QueueOpts -> QueueOpts -> QueueOpts
max :: QueueOpts -> QueueOpts -> QueueOpts
$cmax :: QueueOpts -> QueueOpts -> QueueOpts
>= :: QueueOpts -> QueueOpts -> Bool
$c>= :: QueueOpts -> QueueOpts -> Bool
> :: QueueOpts -> QueueOpts -> Bool
$c> :: QueueOpts -> QueueOpts -> Bool
<= :: QueueOpts -> QueueOpts -> Bool
$c<= :: QueueOpts -> QueueOpts -> Bool
< :: QueueOpts -> QueueOpts -> Bool
$c< :: QueueOpts -> QueueOpts -> Bool
compare :: QueueOpts -> QueueOpts -> Ordering
$ccompare :: QueueOpts -> QueueOpts -> Ordering
Ord, ReadPrec [QueueOpts]
ReadPrec QueueOpts
Int -> ReadS QueueOpts
ReadS [QueueOpts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueueOpts]
$creadListPrec :: ReadPrec [QueueOpts]
readPrec :: ReadPrec QueueOpts
$creadPrec :: ReadPrec QueueOpts
readList :: ReadS [QueueOpts]
$creadList :: ReadS [QueueOpts]
readsPrec :: Int -> ReadS QueueOpts
$creadsPrec :: Int -> ReadS QueueOpts
Read, Int -> QueueOpts -> ShowS
[QueueOpts] -> ShowS
QueueOpts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueueOpts] -> ShowS
$cshowList :: [QueueOpts] -> ShowS
show :: QueueOpts -> String
$cshow :: QueueOpts -> String
showsPrec :: Int -> QueueOpts -> ShowS
$cshowsPrec :: Int -> QueueOpts -> ShowS
Show)
newQueue :: QueueOpts
newQueue :: QueueOpts
newQueue = Text -> Bool -> Bool -> Bool -> Bool -> FieldTable -> QueueOpts
QueueOpts Text
"" Bool
False Bool
True Bool
False Bool
False (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
declareQueue :: Channel -> QueueOpts -> IO (Text, Int, Int)
declareQueue :: Channel -> QueueOpts -> IO (Text, Int, Int)
declareQueue Channel
chan QueueOpts
queue = do
SimpleMethod (Queue_declare_ok (ShortString Text
qName) Word32
messageCount Word32
consumerCount) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt
-> ShortString
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> FieldTable
-> MethodPayload
Queue_declare
ShortInt
1
(Text -> ShortString
ShortString forall a b. (a -> b) -> a -> b
$ QueueOpts -> Text
queueName QueueOpts
queue)
(QueueOpts -> Bool
queuePassive QueueOpts
queue)
(QueueOpts -> Bool
queueDurable QueueOpts
queue)
(QueueOpts -> Bool
queueExclusive QueueOpts
queue)
(QueueOpts -> Bool
queueAutoDelete QueueOpts
queue)
Bool
False
(QueueOpts -> FieldTable
queueHeaders QueueOpts
queue)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
qName, forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
messageCount, forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
consumerCount)
bindQueue :: Channel -> Text -> Text -> Text -> IO ()
bindQueue :: Channel -> Text -> Text -> Text -> IO ()
bindQueue Channel
chan Text
queue Text
exchange Text
routingKey = Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindQueue' Channel
chan Text
queue Text
exchange Text
routingKey (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
bindQueue' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindQueue' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
bindQueue' Channel
chan Text
queue Text
exchange Text
routingKey FieldTable
args = do
(SimpleMethod MethodPayload
Queue_bind_ok) <- Channel -> Assembly -> IO Assembly
request Channel
chan (MethodPayload -> Assembly
SimpleMethod (ShortInt
-> ShortString
-> ShortString
-> ShortString
-> Bool
-> FieldTable
-> MethodPayload
Queue_bind
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
(Text -> ShortString
ShortString Text
exchange)
(Text -> ShortString
ShortString Text
routingKey)
Bool
False
FieldTable
args
))
forall (m :: * -> *) a. Monad m => a -> m a
return ()
unbindQueue :: Channel -> Text -> Text -> Text -> IO ()
unbindQueue :: Channel -> Text -> Text -> Text -> IO ()
unbindQueue Channel
chan Text
queue Text
exchange Text
routingKey =
Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindQueue' Channel
chan Text
queue Text
exchange Text
routingKey (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
unbindQueue' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindQueue' :: Channel -> Text -> Text -> Text -> FieldTable -> IO ()
unbindQueue' Channel
chan Text
queue Text
exchange Text
routingKey FieldTable
args = do
SimpleMethod MethodPayload
Queue_unbind_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt
-> ShortString
-> ShortString
-> ShortString
-> FieldTable
-> MethodPayload
Queue_unbind
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
(Text -> ShortString
ShortString Text
exchange)
(Text -> ShortString
ShortString Text
routingKey)
FieldTable
args
forall (m :: * -> *) a. Monad m => a -> m a
return ()
purgeQueue :: Channel -> Text -> IO Word32
purgeQueue :: Channel -> Text -> IO Word32
purgeQueue Channel
chan Text
queue = do
SimpleMethod (Queue_purge_ok Word32
msgCount) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt -> ShortString -> Bool -> MethodPayload
Queue_purge
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
Bool
False
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
msgCount
deleteQueue :: Channel -> Text -> IO Word32
deleteQueue :: Channel -> Text -> IO Word32
deleteQueue Channel
chan Text
queue = do
SimpleMethod (Queue_delete_ok Word32
msgCount) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt -> ShortString -> Bool -> Bool -> Bool -> MethodPayload
Queue_delete
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
Bool
False
Bool
False
Bool
False
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
msgCount
newMsg :: Message
newMsg :: Message
newMsg = ByteString
-> Maybe DeliveryMode
-> Maybe Timestamp
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Octet
-> Maybe Text
-> Maybe Text
-> Maybe FieldTable
-> Message
Message ByteString
BL.empty forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing
data Ack = Ack | NoAck
deriving (Ack -> Ack -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ack -> Ack -> Bool
$c/= :: Ack -> Ack -> Bool
== :: Ack -> Ack -> Bool
$c== :: Ack -> Ack -> Bool
Eq, Eq Ack
Ack -> Ack -> Bool
Ack -> Ack -> Ordering
Ack -> Ack -> Ack
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ack -> Ack -> Ack
$cmin :: Ack -> Ack -> Ack
max :: Ack -> Ack -> Ack
$cmax :: Ack -> Ack -> Ack
>= :: Ack -> Ack -> Bool
$c>= :: Ack -> Ack -> Bool
> :: Ack -> Ack -> Bool
$c> :: Ack -> Ack -> Bool
<= :: Ack -> Ack -> Bool
$c<= :: Ack -> Ack -> Bool
< :: Ack -> Ack -> Bool
$c< :: Ack -> Ack -> Bool
compare :: Ack -> Ack -> Ordering
$ccompare :: Ack -> Ack -> Ordering
Ord, ReadPrec [Ack]
ReadPrec Ack
Int -> ReadS Ack
ReadS [Ack]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ack]
$creadListPrec :: ReadPrec [Ack]
readPrec :: ReadPrec Ack
$creadPrec :: ReadPrec Ack
readList :: ReadS [Ack]
$creadList :: ReadS [Ack]
readsPrec :: Int -> ReadS Ack
$creadsPrec :: Int -> ReadS Ack
Read, Int -> Ack -> ShowS
[Ack] -> ShowS
Ack -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ack] -> ShowS
$cshowList :: [Ack] -> ShowS
show :: Ack -> String
$cshow :: Ack -> String
showsPrec :: Int -> Ack -> ShowS
$cshowsPrec :: Int -> Ack -> ShowS
Show)
ackToBool :: Ack -> Bool
ackToBool :: Ack -> Bool
ackToBool Ack
Ack = Bool
False
ackToBool Ack
NoAck = Bool
True
consumeMsgs :: Channel -> Text -> Ack -> ((Message,Envelope) -> IO ()) -> IO ConsumerTag
consumeMsgs :: Channel -> Text -> Ack -> ((Message, Envelope) -> IO ()) -> IO Text
consumeMsgs Channel
chan Text
queue Ack
ack (Message, Envelope) -> IO ()
callback =
Channel
-> Text
-> Ack
-> ((Message, Envelope) -> IO ())
-> (Text -> IO ())
-> FieldTable
-> IO Text
consumeMsgs' Channel
chan Text
queue Ack
ack (Message, Envelope) -> IO ()
callback (\Text
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Map Text FieldValue -> FieldTable
FieldTable forall k a. Map k a
M.empty)
consumeMsgs' :: Channel -> Text -> Ack -> ((Message,Envelope) -> IO ()) -> (ConsumerTag -> IO ()) -> FieldTable -> IO ConsumerTag
consumeMsgs' :: Channel
-> Text
-> Ack
-> ((Message, Envelope) -> IO ())
-> (Text -> IO ())
-> FieldTable
-> IO Text
consumeMsgs' Channel
chan Text
queue Ack
ack (Message, Envelope) -> IO ()
callback Text -> IO ()
cancelCB FieldTable
args = do
Text
newConsumerTag <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) forall a b. (a -> b) -> a -> b
$ forall a b. MVar a -> (a -> IO (a, b)) -> IO b
modifyMVar (Channel -> MVar Int
lastConsumerTag Channel
chan) forall a b. (a -> b) -> a -> b
$ \Int
c -> forall (m :: * -> *) a. Monad m => a -> m a
return (Int
cforall a. Num a => a -> a -> a
+Int
1,Int
cforall a. Num a => a -> a -> a
+Int
1)
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ (Channel
-> MVar (Map Text ((Message, Envelope) -> IO (), Text -> IO ()))
consumers Channel
chan) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
newConsumerTag ((Message, Envelope) -> IO ()
callback, Text -> IO ()
cancelCB)
Channel -> Assembly -> IO ()
writeAssembly Channel
chan (MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt
-> ShortString
-> ShortString
-> Bool
-> Bool
-> Bool
-> Bool
-> FieldTable
-> MethodPayload
Basic_consume
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
(Text -> ShortString
ShortString Text
newConsumerTag)
Bool
False
(Ack -> Bool
ackToBool Ack
ack)
Bool
False
Bool
True
FieldTable
args
)
forall (m :: * -> *) a. Monad m => a -> m a
return Text
newConsumerTag
cancelConsumer :: Channel -> ConsumerTag -> IO ()
cancelConsumer :: Channel -> Text -> IO ()
cancelConsumer Channel
chan Text
consumerTag = do
SimpleMethod (Basic_cancel_ok ShortString
_) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortString -> Bool -> MethodPayload
Basic_cancel
(Text -> ShortString
ShortString Text
consumerTag)
Bool
False
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ (Channel
-> MVar (Map Text ((Message, Envelope) -> IO (), Text -> IO ()))
consumers Channel
chan) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => k -> Map k a -> Map k a
M.delete Text
consumerTag
publishMsg :: Channel -> Text -> Text -> Message -> IO (Maybe Int)
publishMsg :: Channel -> Text -> Text -> Message -> IO (Maybe Int)
publishMsg Channel
chan Text
exchange Text
routingKey Message
msg = Channel -> Text -> Text -> Bool -> Message -> IO (Maybe Int)
publishMsg' Channel
chan Text
exchange Text
routingKey Bool
False Message
msg
publishMsg' :: Channel -> Text -> Text -> Bool -> Message -> IO (Maybe Int)
publishMsg' :: Channel -> Text -> Text -> Bool -> Message -> IO (Maybe Int)
publishMsg' Channel
chan Text
exchange Text
routingKey Bool
mandatory Message
msg = do
forall a b. MVar a -> (a -> IO (a, b)) -> IO b
modifyMVar (Channel -> MVar Int
nextPublishSeqNum Channel
chan) forall a b. (a -> b) -> a -> b
$ \Int
nxtSeqNum -> do
Channel -> Assembly -> IO ()
writeAssembly Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> ContentHeaderProperties -> ByteString -> Assembly
ContentMethod
(ShortInt
-> ShortString -> ShortString -> Bool -> Bool -> MethodPayload
Basic_publish
ShortInt
1
(Text -> ShortString
ShortString Text
exchange)
(Text -> ShortString
ShortString Text
routingKey)
Bool
mandatory
Bool
False
)
(Maybe ShortString
-> Maybe ShortString
-> Maybe FieldTable
-> Maybe Octet
-> Maybe Octet
-> Maybe ShortString
-> Maybe ShortString
-> Maybe ShortString
-> Maybe ShortString
-> Maybe Timestamp
-> Maybe ShortString
-> Maybe ShortString
-> Maybe ShortString
-> Maybe ShortString
-> ContentHeaderProperties
CHBasic
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgContentType Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgContentEncoding Message
msg)
(Message -> Maybe FieldTable
msgHeaders Message
msg)
(DeliveryMode -> Octet
deliveryModeToInt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe DeliveryMode
msgDeliveryMode Message
msg)
(Message -> Maybe Octet
msgPriority Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgCorrelationID Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgReplyTo Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgExpiration Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgID Message
msg)
(Message -> Maybe Timestamp
msgTimestamp Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgType Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgUserID Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgApplicationID Message
msg)
(Text -> ShortString
ShortString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message -> Maybe Text
msgClusterID Message
msg)
)
(Message -> ByteString
msgBody Message
msg)
if Int
nxtSeqNum forall a. Eq a => a -> a -> Bool
/= Int
0
then do
forall a. STM a -> IO a
atomically forall a b. (a -> b) -> a -> b
$ forall a. TVar a -> (a -> a) -> STM ()
modifyTVar' (Channel -> TVar IntSet
unconfirmedSet Channel
chan) forall a b. (a -> b) -> a -> b
$ \IntSet
uSet -> Int -> IntSet -> IntSet
IntSet.insert Int
nxtSeqNum IntSet
uSet
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Enum a => a -> a
succ Int
nxtSeqNum, forall a. a -> Maybe a
Just Int
nxtSeqNum)
else forall (m :: * -> *) a. Monad m => a -> m a
return (Int
0, forall a. Maybe a
Nothing)
getMsg :: Channel -> Ack -> Text -> IO (Maybe (Message, Envelope))
getMsg :: Channel -> Ack -> Text -> IO (Maybe (Message, Envelope))
getMsg Channel
chan Ack
ack Text
queue = do
Assembly
ret <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ ShortInt -> ShortString -> Bool -> MethodPayload
Basic_get
ShortInt
1
(Text -> ShortString
ShortString Text
queue)
(Ack -> Bool
ackToBool Ack
ack)
case Assembly
ret of
ContentMethod (Basic_get_ok Timestamp
deliveryTag Bool
redelivered (ShortString Text
exchange) (ShortString Text
routingKey) Word32
_) ContentHeaderProperties
properties ByteString
body ->
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just (ContentHeaderProperties -> ByteString -> Message
msgFromContentHeaderProperties ContentHeaderProperties
properties ByteString
body,
Envelope {envDeliveryTag :: Timestamp
envDeliveryTag = Timestamp
deliveryTag, envRedelivered :: Bool
envRedelivered = Bool
redelivered,
envExchangeName :: Text
envExchangeName = Text
exchange, envRoutingKey :: Text
envRoutingKey = Text
routingKey, envChannel :: Channel
envChannel = Channel
chan})
Assembly
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
ackMsg :: Channel -> LongLongInt -> Bool -> IO ()
ackMsg :: Channel -> Timestamp -> Bool -> IO ()
ackMsg Channel
chan Timestamp
deliveryTag Bool
multiple =
Channel -> Assembly -> IO ()
writeAssembly Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ Timestamp -> Bool -> MethodPayload
Basic_ack
Timestamp
deliveryTag
Bool
multiple
ackEnv :: Envelope -> IO ()
ackEnv :: Envelope -> IO ()
ackEnv Envelope
env = Channel -> Timestamp -> Bool -> IO ()
ackMsg (Envelope -> Channel
envChannel Envelope
env) (Envelope -> Timestamp
envDeliveryTag Envelope
env) Bool
False
nackMsg :: Channel -> LongLongInt -> Bool -> Bool -> IO ()
nackMsg :: Channel -> Timestamp -> Bool -> Bool -> IO ()
nackMsg Channel
chan Timestamp
deliveryTag Bool
multiple Bool
requeue =
Channel -> Assembly -> IO ()
writeAssembly Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ Timestamp -> Bool -> Bool -> MethodPayload
Basic_nack
Timestamp
deliveryTag
Bool
multiple
Bool
requeue
nackEnv :: Envelope -> IO ()
nackEnv :: Envelope -> IO ()
nackEnv Envelope
env = Channel -> Timestamp -> Bool -> Bool -> IO ()
nackMsg (Envelope -> Channel
envChannel Envelope
env) (Envelope -> Timestamp
envDeliveryTag Envelope
env) Bool
False Bool
False
rejectMsg :: Channel -> LongLongInt -> Bool -> IO ()
rejectMsg :: Channel -> Timestamp -> Bool -> IO ()
rejectMsg Channel
chan Timestamp
deliveryTag Bool
requeue =
Channel -> Assembly -> IO ()
writeAssembly Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ Timestamp -> Bool -> MethodPayload
Basic_reject
Timestamp
deliveryTag
Bool
requeue
rejectEnv :: Envelope
-> Bool
-> IO ()
rejectEnv :: Envelope -> Bool -> IO ()
rejectEnv Envelope
env Bool
requeue = Channel -> Timestamp -> Bool -> IO ()
rejectMsg (Envelope -> Channel
envChannel Envelope
env) (Envelope -> Timestamp
envDeliveryTag Envelope
env) Bool
requeue
recoverMsgs :: Channel -> Bool -> IO ()
recoverMsgs :: Channel -> Bool -> IO ()
recoverMsgs Channel
chan Bool
requeue = do
SimpleMethod MethodPayload
Basic_recover_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ Bool -> MethodPayload
Basic_recover
Bool
requeue
forall (m :: * -> *) a. Monad m => a -> m a
return ()
txSelect :: Channel -> IO ()
txSelect :: Channel -> IO ()
txSelect Channel
chan = do
SimpleMethod MethodPayload
Tx_select_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod MethodPayload
Tx_select
forall (m :: * -> *) a. Monad m => a -> m a
return ()
txCommit :: Channel -> IO ()
txCommit :: Channel -> IO ()
txCommit Channel
chan = do
SimpleMethod MethodPayload
Tx_commit_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod MethodPayload
Tx_commit
forall (m :: * -> *) a. Monad m => a -> m a
return ()
txRollback :: Channel -> IO ()
txRollback :: Channel -> IO ()
txRollback Channel
chan = do
SimpleMethod MethodPayload
Tx_rollback_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod MethodPayload
Tx_rollback
forall (m :: * -> *) a. Monad m => a -> m a
return ()
confirmSelect :: Channel -> Bool -> IO ()
confirmSelect :: Channel -> Bool -> IO ()
confirmSelect Channel
chan Bool
nowait = do
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ (Channel -> MVar Int
nextPublishSeqNum Channel
chan) forall a b. (a -> b) -> a -> b
$ \Int
seqn -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Int
seqn forall a. Eq a => a -> a -> Bool
== Int
0 then Int
1 else Int
seqn
if Bool
nowait
then Channel -> Assembly -> IO ()
writeAssembly Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod (Bool -> MethodPayload
Confirm_select Bool
True)
else do
(SimpleMethod MethodPayload
Confirm_select_ok) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod (Bool -> MethodPayload
Confirm_select Bool
False)
forall (m :: * -> *) a. Monad m => a -> m a
return ()
waitForConfirms :: Channel -> IO ConfirmationResult
waitForConfirms :: Channel -> IO ConfirmationResult
waitForConfirms Channel
chan = forall a. STM a -> IO a
atomically forall a b. (a -> b) -> a -> b
$ (IntSet, IntSet) -> ConfirmationResult
Complete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Channel -> STM (IntSet, IntSet)
waitForAllConfirms Channel
chan
waitForConfirmsUntil :: Channel -> Int -> IO ConfirmationResult
waitForConfirmsUntil :: Channel -> Int -> IO ConfirmationResult
waitForConfirmsUntil Channel
chan Int
timeout = do
TVar Bool
delay <- Int -> IO (TVar Bool)
registerDelay Int
timeout
let partial :: STM ConfirmationResult
partial = do
Bool
expired <- forall a. TVar a -> STM a
readTVar TVar Bool
delay
if Bool
expired
then (IntSet, IntSet, IntSet) -> ConfirmationResult
Partial forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,,)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. TVar a -> a -> STM a
swapTVar (Channel -> TVar IntSet
ackedSet Channel
chan) IntSet
IntSet.empty
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. TVar a -> a -> STM a
swapTVar (Channel -> TVar IntSet
nackedSet Channel
chan) IntSet
IntSet.empty
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. TVar a -> STM a
readTVar (Channel -> TVar IntSet
unconfirmedSet Channel
chan))
else forall a. STM a
retry
complete :: STM ConfirmationResult
complete = (IntSet, IntSet) -> ConfirmationResult
Complete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Channel -> STM (IntSet, IntSet)
waitForAllConfirms Channel
chan
forall a. STM a -> IO a
atomically forall a b. (a -> b) -> a -> b
$ STM ConfirmationResult
complete forall a. STM a -> STM a -> STM a
`orElse` STM ConfirmationResult
partial
addConfirmationListener :: Channel -> ((Word64, Bool, AckType) -> IO ()) -> IO ()
addConfirmationListener :: Channel -> ((Timestamp, Bool, AckType) -> IO ()) -> IO ()
addConfirmationListener Channel
chan (Timestamp, Bool, AckType) -> IO ()
handler =
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ (Channel -> MVar [(Timestamp, Bool, AckType) -> IO ()]
confirmListeners Channel
chan) forall a b. (a -> b) -> a -> b
$ \[(Timestamp, Bool, AckType) -> IO ()]
listeners -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Timestamp, Bool, AckType) -> IO ()
handlerforall a. a -> [a] -> [a]
:[(Timestamp, Bool, AckType) -> IO ()]
listeners
flow :: Channel -> Bool -> IO ()
flow :: Channel -> Bool -> IO ()
flow Channel
chan Bool
active = do
SimpleMethod (Channel_flow_ok Bool
_) <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod (Bool -> MethodPayload
Channel_flow Bool
active)
forall (m :: * -> *) a. Monad m => a -> m a
return ()
defaultConnectionOpts :: ConnectionOpts
defaultConnectionOpts :: ConnectionOpts
defaultConnectionOpts = [(String, PortNumber)]
-> Text
-> [SASLMechanism]
-> Maybe Word32
-> Maybe ShortInt
-> Maybe ShortInt
-> Maybe TLSSettings
-> Maybe Text
-> ConnectionOpts
ConnectionOpts [(String
"localhost", PortNumber
5672)] Text
"/" [Text -> Text -> SASLMechanism
plain Text
"guest" Text
"guest"] (forall a. a -> Maybe a
Just Word32
131072) forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing
openConnection :: String -> Text -> Text -> Text -> IO Connection
openConnection :: String -> Text -> Text -> Text -> IO Connection
openConnection String
host = String -> PortNumber -> Text -> Text -> Text -> IO Connection
openConnection' String
host PortNumber
5672
openConnection' :: String -> PortNumber -> Text -> Text -> Text -> IO Connection
openConnection' :: String -> PortNumber -> Text -> Text -> Text -> IO Connection
openConnection' String
host PortNumber
port Text
vhost Text
loginName Text
loginPassword = ConnectionOpts -> IO Connection
openConnection'' forall a b. (a -> b) -> a -> b
$ ConnectionOpts
defaultConnectionOpts {
coServers :: [(String, PortNumber)]
coServers = [(String
host, PortNumber
port)],
coVHost :: Text
coVHost = Text
vhost,
coAuth :: [SASLMechanism]
coAuth = [Text -> Text -> SASLMechanism
plain Text
loginName Text
loginPassword]
}
plain :: Text -> Text -> SASLMechanism
plain :: Text -> Text -> SASLMechanism
plain Text
loginName Text
loginPassword = Text
-> ByteString
-> Maybe (ByteString -> IO ByteString)
-> SASLMechanism
SASLMechanism Text
"PLAIN" ByteString
initialResponse forall a. Maybe a
Nothing
where
nul :: Char
nul = Char
'\0'
initialResponse :: ByteString
initialResponse = Text -> ByteString
E.encodeUtf8 forall a b. (a -> b) -> a -> b
$ Char -> Text -> Text
T.cons Char
nul Text
loginName Text -> Text -> Text
`T.append` Char -> Text -> Text
T.cons Char
nul Text
loginPassword
amqplain :: Text -> Text -> SASLMechanism
amqplain :: Text -> Text -> SASLMechanism
amqplain Text
loginName Text
loginPassword = Text
-> ByteString
-> Maybe (ByteString -> IO ByteString)
-> SASLMechanism
SASLMechanism Text
"AMQPLAIN" ByteString
initialResponse forall a. Maybe a
Nothing
where
initialResponse :: ByteString
initialResponse = ByteString -> ByteString
toStrict forall a b. (a -> b) -> a -> b
$ Int64 -> ByteString -> ByteString
BL.drop Int64
4 forall a b. (a -> b) -> a -> b
$ Put -> ByteString
runPut forall a b. (a -> b) -> a -> b
$ forall t. Binary t => t -> Put
put forall a b. (a -> b) -> a -> b
$ Map Text FieldValue -> FieldTable
FieldTable forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Text
"LOGIN",ByteString -> FieldValue
FVString forall a b. (a -> b) -> a -> b
$ Text -> ByteString
E.encodeUtf8 Text
loginName), (Text
"PASSWORD", ByteString -> FieldValue
FVString forall a b. (a -> b) -> a -> b
$ Text -> ByteString
E.encodeUtf8 Text
loginPassword)]
rabbitCRdemo :: Text -> Text -> SASLMechanism
rabbitCRdemo :: Text -> Text -> SASLMechanism
rabbitCRdemo Text
loginName Text
loginPassword = Text
-> ByteString
-> Maybe (ByteString -> IO ByteString)
-> SASLMechanism
SASLMechanism Text
"RABBIT-CR-DEMO" ByteString
initialResponse (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const IO ByteString
challengeResponse)
where
initialResponse :: ByteString
initialResponse = Text -> ByteString
E.encodeUtf8 Text
loginName
challengeResponse :: IO ByteString
challengeResponse = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> ByteString
E.encodeUtf8 Text
"My password is " ByteString -> ByteString -> ByteString
`BS.append` Text -> ByteString
E.encodeUtf8 Text
loginPassword
qos :: Channel -> Word32 -> Word16 -> Bool -> IO ()
qos :: Channel -> Word32 -> ShortInt -> Bool -> IO ()
qos Channel
chan Word32
prefetchSize ShortInt
prefetchCount Bool
global = do
SimpleMethod MethodPayload
Basic_qos_ok <- Channel -> Assembly -> IO Assembly
request Channel
chan forall a b. (a -> b) -> a -> b
$ MethodPayload -> Assembly
SimpleMethod forall a b. (a -> b) -> a -> b
$ Word32 -> ShortInt -> Bool -> MethodPayload
Basic_qos
Word32
prefetchSize
ShortInt
prefetchCount
Bool
global
forall (m :: * -> *) a. Monad m => a -> m a
return ()
fromURI :: String -> ConnectionOpts
fromURI :: String -> ConnectionOpts
fromURI String
uri = ConnectionOpts
defaultConnectionOpts {
coServers :: [(String, PortNumber)]
coServers = [(String, PortNumber)]
hostPorts',
coVHost :: Text
coVHost = String -> Text
T.pack String
vhost,
coAuth :: [SASLMechanism]
coAuth = [Text -> Text -> SASLMechanism
plain (String -> Text
T.pack String
uid) (String -> Text
T.pack String
pw)],
coTLSSettings :: Maybe TLSSettings
coTLSSettings = if Bool
tls then forall a. a -> Maybe a
Just TLSSettings
TLSTrusted else forall a. Maybe a
Nothing
}
where ([(String, Int)]
hostPorts, String
uid, String
pw, String
vhost, Bool
tls) = String -> ([(String, Int)], String, String, String, Bool)
fromURI' String
uri
hostPorts' :: [(String, PortNumber)]
hostPorts' = [(String
h, forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
p) | (String
h, Int
p) <- [(String, Int)]
hostPorts]
fromURI' :: String -> ([(String, Int)], String, String, String, Bool)
fromURI' :: String -> ([(String, Int)], String, String, String, Bool)
fromURI' String
uri = (Int -> String -> (String, Int)
fromHostPort Int
dport forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
hstPorts,
ShowS
unEscapeString (forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
==Char
'/') String
uid), ShowS
unEscapeString String
pw,
ShowS
unEscapeString String
vhost, Bool
tls)
where (String
pre :String
suf : [String]
_) = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"@" (String
uri forall a. [a] -> [a] -> [a]
++ String
"@" )
(String
pro :String
uid' :String
pw':[String]
_) = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
":" (String
pre forall a. [a] -> [a] -> [a]
++ String
"::")
(String
hnp :String
thost: [String]
_) = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"/" (String
suf forall a. [a] -> [a] -> [a]
++ String
"/" )
hstPorts :: [String]
hstPorts = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"," String
hnp
vhost :: String
vhost = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
thost then String
"/" else String
thost
dport :: Int
dport = if String
pro forall a. Eq a => a -> a -> Bool
== String
"amqps" then Int
5671 else Int
5672
uid :: String
uid = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
uid' then String
"guest" else String
uid'
pw :: String
pw = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
pw' then String
"guest" else String
pw'
tls :: Bool
tls = String
pro forall a. Eq a => a -> a -> Bool
== String
"amqps"
fromHostPort :: Int -> String -> (String, Int)
fromHostPort :: Int -> String -> (String, Int)
fromHostPort Int
dport String
hostPort = (ShowS
unEscapeString String
host, Int
nport)
where
(String
hst':String
port : [String]
_) = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
":" (String
hostPort forall a. [a] -> [a] -> [a]
++ String
":" )
host :: String
host = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
hst' then String
"localhost" else String
hst'
nport :: Int
nport = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
port then Int
dport else forall a. Read a => String -> a
read String
port