Skip to content
Advertisement

Systemd consumer service starts before broker (RabbitMQ )

I have a RabbitMQ server set up on my raspberry Pi and I want the same device to run a consumer to handle messages to one of my queues. I first tried executing it from the crontab but realized later that running it as a systemd service may be a better idea. This is my first time setting up a systemd service so I may be overseeing something trivial.

My queue_listener.service file looks like this.

JavaScript

After creating the service file I started the service by running the following commands.

JavaScript

The service starts and I can see the consumer in the RabbitMQ Management interface.

But when I reboot my device, the service doesn’t start. Below are the contents of the syslog after reboot.

JavaScript

My consumer service seems to start before the RabbitMQ broker is up. What am I doing wrong? Should I go about this some other way?

Advertisement

Answer

Replace Wants with Requires, Wants is meaning good to have while Requires is a must.

Also, make sure the rabbitmq-server.service is in rabbitmq-server.target. If not, replace rabbitmq-server.target with rabbitmq-server.service

Reference: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement