[rabbitmq-discuss] Synchronous confirmation of delivery to the queue

Andrius Norkaitis andrius.norkaitis at oryo.lt
Mon Jul 5 21:39:54 BST 2010

Thanks Matthew.

I tried it, but BasicPublish and TxCommit completes event if there are no
queues to route.

public bool Publish() {
	bool Mandatory = true; Immediate = false;
	ch.BasicPublish("direct", routingKey,Mandatory, Immediate,
basicProperties, body);
	return true;
	catch { return false; }

I always get TRUE event I there is no consumer/query available.
How to detect that message wasn't published to the queue in same method
calling BasicPublish? I need to return bool flag after trying to publish.

If it is possible only in asynchronous matter using BasicReturn event then I
think I have two options:
1. Lock thread after calling BasicPublish for limited time or while
BasicReturn is returned. (Theading is hard .. Is it good way?)
2. Because I use autodelete query I can check is query available by calling:

bool isConsumerAvailable = false;
ch.QueueDelete(routingKey, true, true, false);
} catch 
//if there is no query I get exception code=404, text="NOT_FOUND"
isConsumerAvailable = true;

What do you think?

-----Original Message-----
From: rabbitmq-discuss-bounces at lists.rabbitmq.com
[mailto:rabbitmq-discuss-bounces at lists.rabbitmq.com] On Behalf Of Matthew
Sent: Monday, July 05, 2010 12:42 PM
To: rabbitmq-discuss at lists.rabbitmq.com
Subject: Re: [rabbitmq-discuss] Synchronous confirmation of delivery to the


On Mon, Jul 05, 2010 at 11:05:00AM +0300, Andrius Norkaitis wrote:
> I have publisher which send message to consumer (using direct exchange 
> and non-durable, autodelete queue) and it needs instant confirmation 
> that the message is routed to the query. I can't use asynchronous 
> IModel.BasicReturn event because I need to know is message routed to 
> query instantly after I call publish method. I think it may be done 
> using autodelete queue, mandatory and immediate message flags, and 
> transactions. If subscriber is offline there would be no query to 
> deliver the message so publisher should get exception after it calls
publish method.

The immediate is pretty meaningless in the context of a transaction, and we
largely reinterpret it as mandatory. I suspect you just want to use
mandatory and a transaction.

However note that if you're doing a commit per publish, performance will be
rather slower. This may not affect your application, depending on its needs.

rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com

More information about the rabbitmq-discuss mailing list