How can I monitor/manage queue in ZeroMQ?

jonstjohn picture jonstjohn · May 20, 2012 · Viewed 17.9k times · Source

First of all, I'm new to ZeroMQ and message queue systems, so what I'm trying to do may be solved through a different approach. I'm designing a messaging system that does the following:

  • Multiple clients connect to a broker and send the id of an item that needs to be processed. The client disconnects immediately and does not wait for a response.

  • The broker sends items to workers, one item per worker, to perform some processing. Each return returns a signal that the processing was completed.

I have a rudimentary system setup which is processing requests/replies correctly, but I'd also like to be able to do the following:

  • Query the broker to see how many processes are actually running on the workers and how many are simply waiting to be run.

  • Have the broker ensure that only one process per id is running - if a duplicate id arrives and that item is not currently being processed by a worker, do not add it to the queue.

I'm using a poll setup with broker/dealer sockets. The code I'm using is very similar to this example from Ian Barber.

My first inclination (although I'm not sure how to implement it in zmq) is to have the broker keep track of the ids that have been received, and those that are actively being processed by workers. It seems that the broker forwards requests to workers immediately, regardless of whether or not they are available to actually run the processing. The workers then queue up the ids and process them in order. This isn't ideal since I'm looking to be able to monitor and control what is going on in the system centrally to achieve reliability.

Anyways, any hints, tips or examples of this type of setup would be greatly appreciated.

Answer

Shaun picture Shaun · May 21, 2012

ZeroMQ is, in my opinion, best used in broker-less designs, for which the library is designed. If you want to monitor the number of items in a queue, or throughput, or whatever, you're going to have to build that into the application/device/producer yourself. Since you're new to messaging, that could get out of hand real quick. Given this, I'd suggest looking into RabbitMQ (or a similar broker), which would provide these services for you out of the box. If you do adopt RabbitMQ (or rather, AMQP), I'd suggest using a fanout exchange for the scenario you describe above.