Skip to content

Instantly share code, notes, and snippets.

@rossdylan
Created July 12, 2014 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossdylan/f877c3c8179d65a3e136 to your computer and use it in GitHub Desktop.
Save rossdylan/f877c3c8179d65a3e136 to your computer and use it in GitHub Desktop.
simple fedmsg haskell thingy
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