The "Data.Binary" module is used here to have fully control over the size and endianess of all data sent across the network. There are several utilities for writing shorts, byte words, longs, 64 bit longs, etc.
Here is a data structure defined with the Binary.Put monad. Our task is write this data to the socket connection.
data AMQPData = AMQPData {
amqpHeaderA :: [Word8],
amqpHeaderB :: Word32
}
instance Binary AMQPData where
put amq = do
BinaryPut.putByteString (pack (amqpHeaderA amq))
BinaryPut.putWord32be (amqpHeaderB amq)
amqInstance :: IO AMQPData
amqInstance = return (AMQPData { amqpHeaderA = (unpack (C.pack amqpHeadA)),
amqpHeaderB = amqpHeadB
})
amq <- amqInstance
let bs_amq = encode amq
-- Through the use of lazy hPut, write out the data to the socket handle
LazyC.hPut h bs_amq
Download
You can download the haskell source for this entry at the following URL including a simple java server to mimic a AMQP node.
http://haskellnotebook.googlecode.com/svn/trunk/haskell/simplenetwork
Resources
(1) http://www.haskell.org/ghc/docs/6.8.2/html/libraries/network/Network.html
(2) http://hackage.haskell.org/packages/archive/binary/0.4.1/doc/html/Data-Binary.html
(3) http://hackage.haskell.org/packages/archive/bytestring/0.9.0.1/doc/html/Data-ByteString.html
6 comments:
Hi, are you subscribed to the RabbitMQ mailing list?
I am not yet, I was thinking about getting on.
You think this might be useful? hehe.
Yes, people would definitely be interested in your client, which would be useful for RabbitMQ. You might also get some feedback. Others have been looking at Haskell clients but you may be the first to actually build one ;-)
It isn't that bad, to be honest. I will definitely consider working on it.
you can join the list here:
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
we welcome people to the discussion :-)
Hi, this may be of interest:
http://haskell.hivefire.com/articles/10830/amqp-client-haskell_proposals/
alexis
Post a Comment