On 04/24/2011 09:18 PM, David Hawthorne wrote:
I'm attempting to use the 0.8 messaging API and I don't see a way to specify the name of the queue to create or listen 
to using this API.  With the older API I could declare the queue with a known name, and thus have multiple clients 
draining the same queue using the same binding (round-robin consumer pattern).  It doesn't look like I can get the name 
of the queue created by createReceiver using Receiver.getName, either, because it only returns the name of the 
exchange.  e.g., if I have an exchange named "test", and I create a receiver with an address like 
"test/foobar.#; { create: always }", Receiver.getName() returns "test", whereas qpidd -t shows me 
the queue is actually "test_e54e7eff-3ae8-4508-b23a-0a0d8b2ef65f".

This almost leads me to the conclusion that it is not meant to be possible to 
round-robin pop messages off of a queue created on a topic exchange.  Is that 
the case?

Is dynamic (i.e. on demand) creation of the exchange and queue important? If so can you elaborate a little on why?

The addressing was designed to keep simple things simple while allowing for cases that didn't fit the common patterns. Understanding what patterns it falls down for, or becomes complex for, will help improve it.

In the above case, I would normally expect that a shared queue would not be created and deleted on demand, but would be created as part of a setup/configuration. Likewise for the exchange.

One other option for dynamically creating (and binding) the shared queue (though not the exchange) would be:

"my-queue; {create: always, node: {x-declare:{auto-delete:True}, x-bindings:[{exchange:test, key:foo.#}]}}"

Note that you probably don't want 'delete: always' for a shared queue as any sender or receiver with that queue as target or source will attempt to delete it on closing. If you want it cleaned up when there are no consumers, then you can use the auto-delet as above.

code example:

{
                string queue_address = "test/foo.# ; { create: always, delete: 
always, node:{ type: topic, durable: false }}";

                 qpid::messaging::Connection connection("127.0.0.1:5672");
                 connection.open();
                 qpid::messaging::Session session = connection.createSession();
                 qpid::messaging::Receiver receiver = 
session.createReceiver(queue_address);

                // attempt to create a second receiver listening on the same 
queue to see what happens
                 qpid::messaging::Receiver receiver2 = 
session.createReceiver(queue_address);

                cout<<  "receiver name is "<<  receiver.getName()<<  endl;
                cout<<  "receiver2 name is "<<  receiver2.getName()<<  endl;

                 qpid::messaging::Message message;
                 qpid::messaging::Duration timeout = 
qpid::messaging::Duration::SECOND;

                int messages_received = 0;

                while (receiver.fetch(msg, timeout))
                        messages_received++;

                while (receiver2.fetch(msg, timeout))
                        messages_received++;

                cout<<  "total messages received is "<<  messages_received<<  
endl;
}

receiver name is test
receiver2 name is test_2
total messages received is 4, expected 2

I keep a count of the total messages received from all receivers, and I'm 
sending exactly 2 messages.  The total messages received should equal 2, but in 
this case it equals 4 because each receiver creates a new queue with a unique 
name and the messages are delivered to each of those, effectively preventing 
the round-robin capability of the old API.

Any help you can give would be greatly appreciated.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to