[rabbitmq-discuss] New and Fundamental Confusion

Bell, Paul M. pbell at syncsort.com
Thu Mar 29 23:45:08 BST 2012


Hi All,

As things are beginning to crystallize in our imminent use of Rabbit, I find myself going over various concepts, just trying to make sure that I understand what we are doing and how we are doing it.

I today stumbled upon a painful confusion which I am sure can be easily dispelled.

I was pondering what it means that a producer writes to an exchange when I realized that I didn't fully understand how this can even work without at least *some* hint as to what queue these messages are destined for. If such a hint, e.g., a queue name, is lacking when the messages are sent to the exchange, then how does it help a consumer to declare the queue name? That is, doesn't the broker need to know that the bunch of messages it is holding should be routed to one or more consumers because they've declared the *same* queue name as the producer?

Using a fanout exchange, my producer code looks like this. Note that the RabbitAdmin object is told via "declare" of both the exchange and the queue. Isn't this just such a "hint?"

                 RabbitAdmin admin = new RabbitAdmin(rabbitTemplate.getConnectionFactory());
                 Exchange ex = new FanoutExchange(exchName, true, false);
                 admin.declareExchange(ex);
                 admin.declareQueue(new Queue(this.queueName));

But in the case of a topic exchange, my producer does this:

                rabbitTemplate = new RabbitTemplate(connectionFactory);
                rabbitAdmin = new RabbitAdmin(rabbitTemplate.getConnectionFactory());
                Queue queue = new Queue("pbJobMgmtRqst", false, false, false);
                rabbitAdmin.declareQueue(queue);
             rabbitTemplate.send(exchangeName, "mgmt.clientID." + routingKeySuffix, msg);

Is the declareQueue here even necessary? The .send() call specifies the exchange, the routing key, and the message. Or, could it be that, for a topic exchange, the broker needs only to pattern match the routing and binding keys, i.e., the producer need not provide any hint of the queue the message is destined for? But, for a fanout exchange where routing and binding is irrelevant, such a hint is needed?

Here's how my lack of understanding first hit me: if two consumers declare the same queue name, then the broker sees them as competing for messages, resulting in an "even" distribution of messages across consumers. But if they declare different queue names, then they are no longer competing, i.e., each will get all messages. I think I understand how this can work when routing and binding matter. But in the fanout exchange case, if one consumer declared "queue1" and the other declared "queue2", then only one of them is going to get messages, right? I mean the case where producer has declared "queue1"...

I am a bit embarrassed that so fundamental a question has escaped me until now. And I am grateful for your help.

Thanks.

-Paul




ATTENTION: -----

The information contained in this message (including any files transmitted with this message) may contain proprietary, trade secret or other  confidential and/or legally privileged information. Any pricing information contained in this message or in any files transmitted with this message is always confidential and cannot be shared with any third parties without prior written approval from Syncsort. This message is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any use, disclosure, copying or distribution of this message, in any form, is strictly prohibited. If you have received this message in error, please immediately notify the sender and/or Syncsort and destroy all copies of this message in your possession, custody or control.


More information about the rabbitmq-discuss mailing list