Search code examples
phprabbitmqjob-queue

Implementing a job queue with rabbitmq


I have built a rabbitmq wrapper which publishes messages to consumers and this is working well.

Can I also build a work queue (like gearman) in rabbitmq which can distribute long running tasks to consumers and the consumers, in turn, notify the publisher with the results.

I guess this would require the publisher to act as a consumer as well which I am not sure how to implement. (Please correct me if I am wrong).

Or, is rabbitmq just not the tool for such case.

Thanks,


Solution

  • RabbitMQ supports this type of pattern. Have a look at the RPC tutorial for a bootstrap of how to implement this pattern.

    It can be implemented in different way depending of your needs:

    • direct reply queue, queue will be created and used only for the reply associated to the request
    • static reply queue which will contain all the replies

    It usually implies a correlation id to correlate request with the reply, or it can be stateless if the reply contains all the necessary information.

    It really depends on your needs.