Can I use exchange in RabbitMQ?

Perhaps I am asking the wrong question here.

what I'm trying to do: several producers drag and drop data in dynamic categories into a named exchange. several consumers must collect this data from these dynamically named queues and act on them.

the problem is that all the consumption examples that I see require that the consumer / subscription has a specific queue name, and my consumers do not know the queue names, and they do not need to know this.

why am i doing this? two reasons:

  • I can have N of these dynamic categories at a time. I would like the queue to serve these categories equally. we currently have one queue (msmq) that accepts all these categories and serves them in FIFO (which means that some categories have been starving for some time).

  • The ability to serve all categories equally, not fifo, allows me to come up with interesting QoS (by default, I understand that Rabbit will cycle through messages).

So, back to my question (if valid): is it possible to use messages from the queue?

+4
source share
2 answers

If you have dynamic subscribers, I would suggest two possible solutions:

Solution 1:

  • Use sharing threads.
  • When posting messages to your exchange, use the required flag.
  • If the message is rejected: create a queue, bind it to a specific routing key and start the subscriber in the queue, republish the rejected message.
  • Use automatic deletion queues, so when a subscriber stops, their queues disappear and the entire auto-creation process can restart.

Solution 2:

  • Use sharing threads.
  • Use the immediate delivery flag when posting messages to your exchange.
  • If the message is rejected: create a queue, bind it to a specific routing key and start the subscriber in the queue, republish the rejected message.
  • Use persistent queues. Since queue creation is idempotent, it is normal to go through the re-creation procedure, the main part here is to ensure that the live subscriber listens in the queue.

If dynamic subscribers are not an option, then this is what I suggest. Assuming you are limited to n subscribers:

  • Define a strategy that hashes dynamic categories in n route keys,
  • Use direct exchange,
  • Bind n to it for n routing keys,
  • One subscriber has one queue.
+5
source

With AMQP, you post messages to Exchange, and you consume messages from the queue. Don't worry about what β€œqueue” means in another messaging technology.

It seems to me that your script can be easily handled by a topic exchange. Publish messages using routing keys such as cat.silly, cat.older, cat.interesting. Consumers then queue using the bind key. *

Thus, all messages published in exchange with any prefix will be copied to the queue due to the template in the binding key. If your consumers are actually sharing, that is, messages should not be copied to multiple queues, then just all consumers use the same queue name. If each consumer uses the same queue name, you can compile it into your code and not worry about what the name is. But when you want to debug a message flow, just create a user who subscribes to a queue named catdebug with the same binding key, cat. *

But if each consumer specializes and wants to choose which messages to process, then each consumer uses a unique queue name. Thus, each consumer will see a copy of each message.

Tag exchange is the best solution for the first attempt, because the semantics of direct and branched exchanges can be easily emulated.

0
source

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


All Articles