Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make RabbitMQ worker listening continuously ?

I am implementing rabbitMQ with more than 3 workers processing. To test it, I need to execute worker file each time, but I don't want that.

I want my worker script to listen all request continuously without manually executing worker file. Many people suggested CRON but I don't want because if previous run hasn't finished then overlap can cause serious issues.

Is there any way to run my worker script continuously in background?

like image 653
Ravirpandey - CS Avatar asked Apr 07 '14 06:04

Ravirpandey - CS


1 Answers

What you actually want is to run your worker as a daemon. The basic idea is to run your task in a loop without any user interaction and write the output into a log file.

This is a complex task and depending on the programming language of your choice there might be a library that will handle that for you.

  • PHP: PHP-Daemon
  • Ruby: Ruby-Daemons
  • Python: Stackoverflow answer
  • Java: Apache Commons daemon

Another useful approach specific to RabbitMQ is to run your worker code as command line program with the RabbitMQ-cli-consumer. This approach will work for any programming language with cli support. Especially for script languages with stability issues like PHP this will be the favorable way to go.

like image 193
Jeff Avatar answered Sep 18 '22 14:09

Jeff