↓ Skip to main content
  1. Home projects/

Messaging experiments: Redis and ZeroMQ

··Index: 8·

Both of these small experiments come from the same week of July 2012.

queue-process: a Redis queue consumer
#

queue-process is a multithreaded C++ client that pops events from a Redis list with a blocking BLPOP and hands them over to a worker, with two Boost threads sharing the work through a mutex and a condition variable. I wrapped the Redis client to catch connection errors and retry every second, so the consumer survives Redis restarts. Source.

req-rep: ZeroMQ between C++ and Python
#

This one is a ZeroMQ request-reply pair. On the C++ side the server dispatches three-letter commands through a command map, where GET returns the current message together with the message ID and ACK<id> confirms that message and moves on to the next one. The client is written in Python with Twisted and txZMQ to loop GET and ACK, but if anything goes wrong (a timeout, for example), it tears down the socket and starts all over again. Source.

Two flows: a Redis list consumed by two threads, and a ZeroMQ request-reply exchange of GET and ACK between a Python client and a C++ server.queue-processRedis listeventsreader threadblocking BLPOPmutex andcondition variableworker threadconnection error: retry every secondreq-repPython clientTwisted, txZMQC++ servercommand mapGETcurrent message and its IDACK<id>: confirm, then the next messageon a timeout the client closes the socket and starts again
The two experiments as message flows

Related