Created
December 28, 2011 23:14
-
-
Save cheecheeo/1530353 to your computer and use it in GitHub Desktop.
RabbitMQ Browsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
- Read n messages from a queue and then put them back on the queue: | |
- rabbitmqbrowse <hostname> <queue_name> <count_of_messages_to_read> | |
- Example usage: | |
- runhaskell rabbitmqbrowse.hs localhost my_queue 3 | |
- | |
- cabal install network amqp | |
-} | |
import qualified System.Environment as Env | |
import qualified Control.Monad as M | |
import qualified Network.BSD as N | |
import qualified Network.Socket as S | |
import qualified Data.ByteString.Lazy.Char8 as BL | |
import qualified Network.AMQP as MQ | |
main :: IO () | |
main = do | |
[host, queueName, count] <- Env.getArgs | |
hostAddress <- S.inet_ntoa =<< N.hostAddress `fmap` N.getHostByName host | |
chan <- MQ.openChannel =<< MQ.openConnection hostAddress "/" "guest" "guest" | |
mapM_ (maybe (return ()) | |
(\(message, envelope) -> do | |
putStrLn $ "received message: " ++ (BL.unpack $ MQ.msgBody message) | |
MQ.rejectMsg chan (MQ.envDeliveryTag envelope) True)) | |
=<< M.replicateM (read count) (MQ.getMsg chan MQ.Ack queueName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment