I have RabbitMQ producer and consumer written in PHP (Symfony 4). Consumer is working as custom symfony 4 command along with bundle php-amqplib/rabbitmq-bundle
Here is issue. I want to be able to set consumer to listen and consume tasks instantly after they appear in queue.
I tried to run it as one-shot systemd service but it's not working wery well.
Systemd:
[Unit]
Description=consumer for rabbitmq
[Service]
Type=oneshot
ExecStart=/bin/sh /var/www/public/rabbit.sh
ExecStop=/usr/bin/pkill -f "rabbitmq:consumer"
RemainAfterExit=yes
StandardOutput=journal
[Install]
WantedBy=multi-user.target
If there is better solution than writing daemon please let me know. I just want to be able to set consumer to listen and consume task instantly after it apear in queue.
rabbitmq:batch:consumerin the background as daemon, maybe set it to quit after a memory limit is reached and have supervisord automatically restart the deamon after that. When you do this, you will always have a consumer running in the background for new messages.bin/console rabbitmq:consumer -m 5 your_queuethe relevant consumer will consume messages as soon as they come in. Check this for supervisor controller RabbitMQ consumers. And inanzzz.com/index.php/posts/rabbitmq