Use Queue directly (without exchange)

374 views
Skip to first unread message

ceelian

unread,
Jul 29, 2011, 8:09:25 AM7/29/11
to carrot-users
Hi,

Is ist possible to interact with Queues directly without using
Exchanges (like in Pika)? I always get an Error like the following:


Traceback (most recent call last):
File "test_actions.py", line 32, in test_method_call
amqp_password='guest')
File "/Users/christian/devel/kombutest.py", line 29, in __init__
self.callback_queue = Queue(channel=channel,exclusive=True)
File "/Library/Python/2.6/site-packages/kombu-1.2.1-py2.6.egg/kombu/
entity.py", line 355, in __init__
self.maybe_bind(channel)
File "/Library/Python/2.6/site-packages/kombu-1.2.1-py2.6.egg/kombu/
abstract.py", line 61, in maybe_bind
self.when_bound()
File "/Library/Python/2.6/site-packages/kombu-1.2.1-py2.6.egg/kombu/
entity.py", line 358, in when_bound
self.exchange = self.exchange(self.channel)
TypeError: 'NoneType' object is not callable


I would like to rewrite the RPC Tutorial on RabbitMQ (http://
www.rabbitmq.com/tutorials/tutorial-six-python.html) with Kombu
instead of Pika.

Best Regards,
Christian

Ask Solem

unread,
Jul 29, 2011, 9:15:48 AM7/29/11
to carrot...@googlegroups.com


Christian,

You are always using an exchange, it's just that if the exchange
name is empty, it will use the default exchange.
I'm a little unclear of how this works exactly, and so are many
other it seems :)

Kombu doesn't support this yet, but it shouldn't be too hard to add.
It may be harder for the virtual transports though, so instead of
relying on this behaviour I create unique queue/exchange names
with UUIDs instead:

# client

from kombu.utils import gen_unique_id

reply_id = gen_unqiue_id()
reply_exchange = Exchange("reply")
callback_queue = Queue(reply_id, reply_exchange,
routing_key=reply_id)

# must declare in advance so reply message isn't
# published before.
callback_queue(channel).declare()

producer = Producer(channel)

producer.publish(body, exchange=some_exchange_name, routing_key=some_key,
reply_to=reply_id)

# worker

producer = Producer(channel)

def reply_callback(body, message):
producer.publish(response, exchange=reply_exchange,
routing_key=message.properties.reply_to,
correlation_id=message.properties.correlation_id)
message.ack()

The only real difference here is that you use a named reply exchange,
instead of the default exchange. For one I find the example a little confusing
in that the same exchange is used for both requests and replies.

In Kombu master I added support for "anonymous" queues, but this
will only work for amqp:


# client

callback_queue_name = Queue()(channel).declare()
producer.publish(body, exchange="", reply_to=callback_queue_name)


# worker

def reply_callback(body, message):
producer.publish(response, exchange="",
routing_key=message.properties.reply_to,
correlation_id=message.properties.correlation_id)
message.ack()


--
Ask Solem
twitter.com/asksol | +44 (0)7713357179

Christian Haintz

unread,
Aug 2, 2011, 9:26:35 AM8/2/11
to carrot...@googlegroups.com
On 29/7/11 15:15, Ask Solem wrote:
>[...]

Ask,

Thank you for the quick response. I also thought about designing of this
RPC paradigma with message queues in general and I will stick to your
named Exchange example. It defines all components explicit and is easy
to follow.

Regards,
Christian

Robert Myers

unread,
Aug 29, 2013, 9:57:47 AM8/29/13
to carrot...@googlegroups.com
I'm looking to do something similar to what the original poster asked, to reproduce the example from the Rabbit MQ page, tutorial 6.

I am unable to find in the current API documentation, at: http://kombu.readthedocs.org/en/latest/reference/index.html where the reply_to is supported.

Is this argument still supported in KOMBU 2.5.14?  Or am I barking up the wrong tree?  I simply need a way to reply to a message delivered to an RPC service, so it can send a response back.  If there's another method in KOMBU I'd appreciate any direction.  I did look at the kombu.pidbox mailbox, but I'm unsure that this meets my needs, but perhaps I'm misreading it.



Thank you. :)

Ask Solem

unread,
Aug 31, 2013, 9:24:38 AM8/31/13
to carrot...@googlegroups.com

On Aug 29, 2013, at 2:57 PM, Robert Myers <ccri...@gmail.com> wrote:

> I'm looking to do something similar to what the original poster asked, to reproduce the example from the Rabbit MQ page, tutorial 6.
>
> I am unable to find in the current API documentation, at: http://kombu.readthedocs.org/en/latest/reference/index.html where the reply_to is supported.
>
> Is this argument still supported in KOMBU 2.5.14? Or am I barking up the wrong tree? I simply need a way to reply to a message delivered to an RPC service, so it can send a response back. If there's another method in KOMBU I'd appreciate any direction. I did look at the kombu.pidbox mailbox, but I'm unsure that this meets my needs, but perhaps I'm misreading it.


reply_to is a message property and properties are specified as keyword arguments
to Producer.publish:


producer.publish(body, …, reply_to=id)



On the consumer side the reply_to is available in Message.properties['reply_to']


--
Ask Solem
twitter.com/asksol

Reply all
Reply to author
Forward
0 new messages