Wednesday, January 9, 2008

More on the AMQP (RabbitMQ) haskell client (and an example)

I am building a AMQP client library to use along with some of the openbotlistprojects. The client library will need to be written in haskell and will be able to communicate with MQ servers like RabbitMQ. That is irrelevant because I am just wrapping my head around haskell networking.

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

You can download the haskell source for this entry at the following URL including a simple java server to mimic a AMQP node.




alexis said...

Hi, are you subscribed to the RabbitMQ mailing list?

Berlin Brown said...

I am not yet, I was thinking about getting on.

You think this might be useful? hehe.

alexis said...

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 ;-)

Berlin Brown said...

It isn't that bad, to be honest. I will definitely consider working on it.

alexis said...

you can join the list here:

we welcome people to the discussion :-)

alexis said...

Hi, this may be of interest: