I have been investigating using RabbitMQ for a publish/subscribe pattern across micro-services where aysnc calls are appropriate but I am having trouble understanding some concepts and could not find any info in the manual.
I'll outline a basic example of how I wish to use it below.
I have a core service for user management. When a user is created I wish to publish an event such as user_created I would like this event to be consumed by multiple different services. For example
- A communications service which handles the sending of the welcome email
- A marketing service which takes the user data and publishes it to a third party data bucket
- A finance service which sets up a new customer statement/account
Each of the services above are their own separate codebase in a few different languages/frameworks.
From what I can tell of the docs for this kind of I will need an exchange where I publish a message like user_created along with any data I wish to send (like the user object)
On each of my services I then set up a consumer script which connects to the exchange and creates a queue and consumes any messages sent.
If my understanding so far is correct my main question comes from how to handle these consumers on the services end. If I am using acknowledgement my understanding is that even if one of my consumers dies the queue and message will not be deleted. Both will persist and wait for the a new consumer indefinitely.
Any number of services will presumably want to consume lots of different messages. Is it okay to have lots of different consumers constantly running?
Primarily the services use PHP so these consumers would maybe look like the below (for the comms service)
sendWelcomeEmail.php
sendGoodbyeEmail.php
sendInvoice.php
So presumably I set up each of these scripts as directed on the tutorials (like here https://www.rabbitmq.com/tutorials/tutorial-three-php.html) and run the scripts as part of the deployment process. I would then need something like supervisor to make sure the consumer is running and if it is not restart it. This could be quite cumbersome having to set a supervisor up for each consumer. Are there better ways to handle things?