Creating a dynamic queue using RabbitMQ

I studied various RabbitMQ topologies, however I could not find a link to create a dynamic queue (aka Declare Queue) issued from the manufacturer. The idea would be to dynamically create queues based on a specific event (for example, an HTTP request). The queue would be temporary with a set of TTL and named after the event identifier. Then the consumer can subscribe to the topic "event. *" And combine all the messages associated with it.

Example:

  • HTTP POST "Create User"
  • manufacturer creates user.ID queue
  • click on all subsequent messages regarding the user in his queue (for example, "Add username", "Add email address" ...)
  • the worker is assigned to the random queue "user. *" and combines everything into a user account
  • the queue is automatically deleted after the expiration of the TTL

Now, is this scenario possible with RabbitMQ?

+4
source share
1 answer

Essentially, you want to use RabbitMQ to buffer messages waiting in a queue set (which is what the message queuing system does by definition). :)

Assuming that you know your lineup is from the consumer, you will not have any problems. There is no restriction that a manufacturer cannot create a queue. As a warning, when the queues end, all messages in the queue are discarded (or, optionally, they can be configured to go into the dead letter queue).

What code have you tried?

Edit

After further clarification (from your comment), you are looking for a โ€œuse patternโ€ against publishing wildcards. RabbitMQ does not currently support this topology ( this post is requesting a similar feature).

What you need to do is periodically list the queues (using the RabbitMQ API); After that, your application can decide which of them to use. When the queue is deleted, the consumer closes automatically.

Special Note It should be understood that what is defined here is an anti-pattern. A typical behavior of a system using queues is to route messages in a queue based on content. Thus, a properly organized system will have a set of workers working in one or more statically defined queues. Different workers may take different lines, depending on specialization. When a series of interactions leads to the publication of messages in the queue, workers assigned to the queues will process messages in the first-time mode (but, as this post discusses, an order cannot be guaranteed with multiple consumers). Then the desired behavior of the system arises as a composition of workers performing various functions working in queues.

+3
source

Source: https://habr.com/ru/post/984950/


All Articles