Another perspective in RabbitMQ queue naming convention

RabbitMQ is a popular open-source message broker that allows applications to communicate with each other asynchronously using various protocols and patterns. One of the key aspects of using RabbitMQ is designing and naming the queues that store and deliver the messages between the producers and consumers. However, there is no definitive or universal rule for naming queues in RabbitMQ, and different developers may have different preferences and conventions.

RabbitMQ queue naming convention commonly used is mostly based on the following principles:

  • The queue name should be descriptive and meaningful, reflecting the content and purpose of the messages in the queue.
  • The queue name should be consistent and follow a standard format that can be easily understood and maintained by other developers.
  • The queue name should be flexible and adaptable, allowing for changes and extensions without breaking the existing functionality or compatibility.

One practice that I commonly use is to have the queue name the same as the listener method name. The goal is to make it a lot easier to understand the event flow in an event driven architecture.

Example:

You have a domain handling user creation with the following microservices

  • user-management-orchestrator-service
  • user-management-storage-service
  • user-management-notification-service

the 3 microservices are communicating using RabbitMQ with the following diagram

The microservice user-management-storage-service has the task of subscribing the user-creation-requested event, and then attempt to insert the user into the database.

If the method of the listener is attemptCreateUserInDatabase, it’s simple to use it as the queue name umss.attempt-create-user-in-database.queue.

This way if you need to trace the message, you’ll instantly know the queue ownership and what the task is attributed to the subscriber.

A side note, to avoid name conflict of the service abbreviation, you can further enhance the name with the name of the associated domain, for example user-management.umss.attempt-create-user-in-database.queue

This short article is intended for developers who have some basic knowledge and experience with RabbitMQ and message brokers in general. It is not a comprehensive guide or tutorial on RabbitMQ, but rather a personal opinion and suggestion on one aspect of using RabbitMQ. The article does not claim to be the best or the only way to name queues in RabbitMQ, and it may not suit every use case or scenario. Readers are encouraged to do their own research and experimentation to find the most suitable queue naming convention for their needs.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *