Created
July 12, 2014 00:04
-
-
Save rossdylan/f877c3c8179d65a3e136 to your computer and use it in GitHub Desktop.
simple fedmsg haskell thingy
This file contains hidden or 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
module Main where | |
import System.ZMQ | |
import Control.Monad (replicateM, forever) | |
import qualified Data.ByteString | |
import Text.Printf | |
type Topics = [String] | |
type MessageHandler = (Data.ByteString.ByteString -> IO ()) | |
subscribeTopics :: SubsType a => Topics -> Socket a -> IO () | |
subscribeTopics topics sock = mapM_ (subscribe sock) topics | |
ingestMessages :: SubsType a => Socket a -> MessageHandler -> IO () | |
ingestMessages socket handler = forever $ receive socket [] >>= handler | |
connectSocket :: String -> Topics -> Context -> IO () | |
connectSocket endpoint topics context= withSocket context Sub $ \subscriber -> do | |
putStrLn $ "Connecting to " ++ endpoint | |
connect subscriber endpoint | |
subscribeTopics topics subscriber | |
ingestMessages subscriber Data.ByteString.putStrLn | |
startContext :: String -> | |
startContext = withContext 1 $ connectSocket | |
main :: IO () | |
main = do | |
withContext 1 $ theThings "tcp://hub.fedoraproject.org:9940" [""] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment