forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emitLog.hs
28 lines (21 loc) · 779 Bytes
/
emitLog.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# OPTIONS -XOverloadedStrings #-}
import Network.AMQP
import qualified Data.ByteString.Lazy.Char8 as BL
import System.Environment (getArgs)
import Text.Printf
logsExchange = "logs"
main :: IO ()
main = do
args <- getArgs
let body = bodyFor args
conn <- openConnection "127.0.0.1" "/" "guest" "guest"
ch <- openChannel conn
declareExchange ch newExchange {exchangeName = logsExchange, exchangeType = "fanout", exchangeDurable = False}
publishMsg ch logsExchange ""
(newMsg {msgBody = (BL.pack body),
msgDeliveryMode = Just NonPersistent})
putStrLn $ printf " [x] Sent '%s'" (body)
closeConnection conn
bodyFor :: [String] -> String
bodyFor [] = "Hello, world!"
bodyFor xs = unwords xs