Wednesday, May 25, 2022

[SOLVED] In Centos 7, how do you permanently consume messages with rabbitmq?

Issue

Good day,

I have just uploaded Symfony 3.4 project (PHP 7.2) to Centos server and my application needs to be connected to RabbitMQ. I want to do that in Centos server rabbitmq is constantly consuming messages. I know how to consume those messages temporarily by running this command: bin/console rabbitmq:consumer messaging . But how could permanently I consume the messages on server? I tried to google but didn't find any useful information

In my application I've installed:

"php-amqplib/php-amqplib": "*",

"php-amqplib/rabbitmq-bundle": "*"

UPDATE:

I achieved my desired situation with the following command:

nohup bin/console rabbitmq:consumer <your-consumer> &


Solution

idk if there's an "official" way of doing it, but as with anything in Linux, you could just write a little daemon to do it, a minimum example would be to add this to your crontab -e

@reboot /bin/bash /project/folder/cronjob_starter.sh

with cronjob_starter.sh containing

#!/bin/bash

if [[  $(screen -ls | grep rabbitmq_daemon) ]]
        then
                echo "rabbitmq_daemon already running!"
                /bin/true
        else
                # echo " rabbitmq_daemon not running!"
                screen -S rabbitmq_daemon -dm
                # workaround for https://savannah.gnu.org/bugs/index.php?54164
                sleep 1
                screen -S rabbitmq_daemon -X stuff "cd /project/folder; bin/console rabbitmq:consumer messaging^M"
fi

then you can inspect your daemon with screen -xS rabbitmq_daemon , or with the Screenie application (honestly idk how to "properly" install Screenie on CentOS, i just run curl https://gist.githubusercontent.com/divinity76/1a583968c997869b27a5ee2c1ed24259/raw/76453e61a92676386589fbb3f4ef0225ac98fb19/screenie.b64 | base64 -d | sudo tee /usr/local/bin/screenie ; sudo chmod 0555 /usr/local/bin/screenie; )

  • if there's an "official" way of doing it tho, you should probably do it the official way instead, i don't know anything about that unfortunately.


Answered By - hanshenrik
Answer Checked By - Marie Seifert (WPSolving Admin)