1 {-# LANGUAGE OverloadedStrings #-}
3 import Paths_amqp_utils ( version )
4 import Data.Version ( showVersion )
5 import System.Environment
6 import qualified Data.Text as T
8 import Network.AMQP.Utils.Options
9 import Network.AMQP.Utils.Helpers
10 import Network.AMQP.Utils.Connection
11 import qualified Data.ByteString.Lazy.Char8 as BL
12 import Data.Word ( Word64 )
18 args <- getArgs >>= parseargs "agitprop"
19 printparam' "client version" $ "amqp-utils " ++ (showVersion version)
20 printparam' "routing key" $ rKey args
21 printparam' "input file" $
22 (inputFile args) ++ if (lineMode args) then " (line-by-line)" else ""
23 messageFile <- BL.readFile (inputFile args)
24 (conn, chan) <- connect args
25 printparam' "confirm mode" $ show $ confirm args
28 confirmSelect chan False
29 addConfirmationListener chan confirmCallback
31 let publishOneMsg f = do
33 (T.pack $ currentExchange args)
36 , msgDeliveryMode = Just Persistent
38 printparam "sent" $ fmap show r
40 then mapM_ publishOneMsg (BL.lines messageFile)
41 else publishOneMsg messageFile
44 then waitForConfirms chan >>= return . show >> return ()
48 -- | The handler for publisher confirms
49 confirmCallback :: (Word64, Bool, AckType) -> IO ()
50 confirmCallback (deliveryTag, isAll, ackType) =
51 printparam' "confirmed"
52 ((show deliveryTag) ++
53 (if isAll then " all " else " this ") ++ (show ackType))