Getting a queue without providing all its properties

I am trying to write a consumer for an existing queue.

RabbbitMQ runs in a separate instance, and a queue named "org-queue" has already been created and is tied to the exchange. org-queue is a strong queue, and it also has some additional features.

Now I need to receive messages from this queue. I use the code below to get a queue instance

conn = Bunny.new conn.start ch = conn.create_channel q = ch.queue("org-queue") 

This generates an error that indicates another long-term property. Bunny seems to use durable = false by default. So I added a solid true as a parameter. Now it indicates the difference between other parameters. Do I need to specify all the parameters to connect to it? Since rabbitMQ is supported in different environments, it's hard for me to get all the properties.

Is there a way to get a list of queues and listen to the required queue in the client, and not connect to the queue in all respects.

+6
source share
3 answers

Have you tried the passive = true parameter in queue ()? A real example is the rabbitmq logstash.: Plugin : a passive tool to check for the existence of a queue, rather than declare it when messages are consumed from it.

+1
source

Based on the documentation here http://reference.rubybunny.info/Bunny/Queue.html and http://reference.rubybunny.info/Bunny/Channel.html

Using the ch.queues() method, you can get the hash of all the queues on this channel. Then, once you find the instance of the queue that you want to connect to, you can use the q.options() method to find out which parameters are in this rabbitmq queue.

There seems to be a round way to do this, but may work. I have not tested this, because at the moment I do not have a rabbitmq server.

+1
source

Maybe there is a way to get it using rabbitmqctl or admin (I forgot the name), so there is queue information. Even so, I would not bother.

There are two possible solutions that come to me.

First decision:

In general, if you want to declare an existing queue, it should be with all the correct parameters. So I have a helper function to declare a specific queue (I use the C ++ client, so the API may be different, but I'm sure the concept is the same). For example, if I have 10 subscribers who consume queue1, and each of them must declare a queue in the same way, I will simply write a utility that declares this queue, and this.


There is one thing before the second decision: maybe this is the case when we come to an error that happens too often :) You don’t need a certain queue to receive messages from this queue. You need a queue and the right binding . When sending a message, you really do not send to the queue, but for exchange, sometimes with a routing key, sometimes without it - let them say it. On the receiving side, you need a queue in order to consume a message, so of course you declare one and bind it to the exchange using a routing key. You do not even need to explicitly specify the name of the queue, the server will provide you with a general option so that you can use it when binding.


Second solution: based on the fact that

It is perfectly legal to associate multiple queues with the same key binding (found here https://www.rabbitmq.com/tutorials/tutorial-four-java.html )

In this way, each of your subscribers can handle the queue the way they want, as long as they link correctly. Of course, these are different queues with different names. I would not recommend . This means that each message is sent, for example, in two queues, and most likely a message (I assume that the precedent here needs to be processed only once per subscriber).

0
source

All Articles