<p>I'd say that if you need strict ordering then the subscriber will have to handle that, perhaps by caching incoming messages as soon as it detects a hole in the sequence flow and starting to process once again once the missing message has been processed. This gets messy soon, however, if you happen to lose another message while you are already waiting for the first one. And so on, recursively.</p>
<p>Are there any other approaches to achieve ordering guarantees?</p>
<div class="gmail_quote">On Jun 15, 2011 6:14 PM, "Emile Joubert" <<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>> wrote:<br type="attribution">> Hi,<br>> <br>> Rabbit preserves order of messages under strict conditions, as<br>
> discussed. Your case does not meet those conditions, so the ordering<br>> guarantees do not apply. The current version of rabbit (2.5.0 at the<br>> time of writing) will therefore not deliver those messages in order<br>
> (unless the queue happens to be empty when requeues take place).<br>> Unfortunately stopping the producer will not change that.<br>> <br>> You could try to meet the conditions under which the broker preserves<br>
> message order or you could detect the problem and attempt to deal with<br>> it downstream.<br>> <br>> <br>> -Emile<br>> <br>> <br>> On 15/06/11 16:31, T-zex wrote:<br>>> Tanks again!<br>>> <br>
>> So, in case we detect that current message sequence number is bigger<br>>> than expected do we need to loop through the queue untill the required<br>>> message is found? Does this mean that producer must be stopped,<br>
>> because all other messages in front of the queue will become unacked<br>>> and will go back to the queue and new ones will appear at the front -<br>>> basically to avoid shuffling.<br>>> <br>>> <br>
>> <br>>> On Wed, Jun 15, 2011 at 4:03 PM, Emile Joubert <<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>> wrote:<br>>>> Hi,<br>>>><br>>>> Message order guarantees only apply along the same path between a single<br>
>>> producer and consumer. The guarantees do not hold if messages get<br>>>> requeued. Rabbit will requeue messages at the back of the queue, i.e.<br>>>> treat it as a new message.<br>>>><br>
>>> Your producer may add a sequence number to messages so that consumers<br>>>> can detect this. Consumers may also inspect the "redelivered" flag to<br>>>> check whether a message has been delivered before.<br>
>>><br>>>><br>>>> -Emile<br>>>><br>>>><br>>>> On 15/06/11 15:34, T-zex wrote:<br>>>>> Thank you Emile.<br>>>>><br>>>>> The thing I'm trying to solve is have a guaranteed order of messages:<br>
>>>> if I fail to ack after BasicGet() the message anyway will go to the<br>>>>> end of the queue. In case noAck = true, there is a risk to lose a<br>>>>> message when a process fails. I can't find a way to make RabbitMQ work<br>
>>>> as a queue in a simple single reader scenario...<br>>>>><br>>>>> On Wed, Jun 15, 2011 at 1:42 PM, Emile Joubert <<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>> wrote:<br>
>>>>> Hi,<br>>>>>><br>>>>>> Yes, if you want to retrieve a single message synchronously then use<br>>>>>> IModel.BasicGet() . BasicConsume() is for asynchronous delivery of<br>
>>>>> messages, which is faster than BasicGet() and often leads to simpler<br>>>>>> client code.<br>>>>>><br>>>>>><br>>>>>><br>>>>>> On 15/06/11 13:35, T-zex wrote:<br>
>>>>>> In my case it doesn't matter if it is IModel.Close() or<br>>>>>>> IModel.ChannelFlow(false) couse the process must be terminated anyway.<br>>>>>>> We need an atomic operation which would ack the message and would not<br>
>>>>>> fetch the other one. It seems that BasicConsume is unable to gurantee<br>>>>>>> that, so maybe BasicGet is a better option?<br>>>>>>><br>>>>>>> On Wed, Jun 15, 2011 at 12:03 PM, Emile Joubert <<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>> wrote:<br>
>>>>>>> Hi,<br>>>>>>>><br>>>>>>>> Prefetch count limits the number of unacknowledged messages, so you<br>>>>>>>> would need to acknowledge the last message to get the next one if the<br>
>>>>>>> prefetch count was set to 1.<br>>>>>>>><br>>>>>>>> You should never need to close the channel for flow control. You can use<br>>>>>>>> IModel.ChannelFlow() if you need to temporarily stop the broker from<br>
>>>>>>> delivering messages. This works independently from the prefetch count.<br>>>>>>>><br>>>>>>>><br>>>>>>>> -Emile<br>>>>>>>><br>
>>>>>>><br>>>>>>>> On 15/06/11 10:55, T-zex wrote:<br>>>>>>>>> Thank you!<br>>>>>>>>><br>>>>>>>>> When prefetch count is set to 1 channel will try to fetch the next<br>
>>>>>>>> message as soon as HandleBasicDeliver returns? Should I invoke<br>>>>>>>>> Channel.Close() on a different thread (to avoid blocking) and then<br>>>>>>>>> return?<br>
>>>>>>>><br>>>>>>>>> On Wed, Jun 15, 2011 at 10:33 AM, Emile Joubert <<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>> wrote:<br>>>>>>>>>> Hi,<br>
>>>>>>>>><br>>>>>>>>>> On 15/06/11 10:08, T-zex wrote:<br>>>>>>>>>>> Hi,<br>>>>>>>>>>><br>>>>>>>>>>> We are overriding DefaultBasicConsumer.HandleBasicDeliver method and<br>
>>>>>>>>>> use IModel.BasicConsume to subscribe to incoming messages:<br>>>>>>>>>>> model.BasicConsume(queue, false, instanceOfDerivedConsumer);<br>>>>>>>>>>><br>
>>>>>>>>>> When application fails to ack a message that message is requeued. How<br>>>>>>>>>>> can I guarantee that BasicConsume is receiving one message at a time?<br>
>>>>>>>>>> How to deterministically stop consuming when application detects that<br>>>>>>>>>>> it is unable to process a message and prevent the second message from<br>
>>>>>>>>>> arriving? How to make sure that there is one and only one unacked<br>>>>>>>>>>> message and that message is at the peak of broker queue.<br>>>>>>>>>><br>
>>>>>>>>> The solution is to set the prefetch count of the channel to 1 using<br>>>>>>>>>> IModel.BasicQos(). Also see<br>>>>>>>>>> <a href="http://www.rabbitmq.com/amqp-0-9-1-quickref.html#basic.qos">http://www.rabbitmq.com/amqp-0-9-1-quickref.html#basic.qos</a> .<br>
>>>>>>>>> Note that rabbit does not implement the prefetch size or global<br>>>>>>>>>> parameters to the same method.<br>> _______________________________________________<br>
> rabbitmq-discuss mailing list<br>> <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>> <a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
</div>