Monday, February 20, 2012

Message Ordering

When I am receiving a batch of message from a queue to process, does it matter if I order by the queuing_order or the message_sequence_number? I want to make sure my messages process in the order in which they were put into the queue, which I know will happen if I process messages one-by-one, but want to make sure that the data I pull and process execute in the order in which they were received.

Tim

Either will do. RECEIVE projects the resultset in the order status, conversation_group, conversation_handle, queueing_order. I'd use the same order in my batch just for consistency (e.g. if the app logic is later moved to a CLR procedure processing a SqlDataReader, the order is unchanged).|||Sounds good, will do.

I did notice something the other day related to batch processing that I think could occur if you are not careful. It may be related to how I am handling the batch...let me know what you think:

I keep a convo open for ~ 90 seconds,or until a new message is sent. When I notice that a convo has gotten too old, I create a new one and process messages on that conversation. When I do this, I send an EndOfStream message that tells my procedures that it is time to end the conversation, and no new messages are sent on that older conversation. The potential problem I see with this is that when I create a new convo and send an EndOfStream message, the new convo starts processing messages right away, even maybe before the EndOfStream message has been processed, and all messages along with that convo processed. This, potentially, could mean that my messages are being processed out of order, which is really something that I can tolerate, but really don't want. Do you think it makes sense to try to add additional logic to prevent this from happening, or is there some other construct, such as a type of conversation lock I could use, to prevent this from happening?
Thanks,
Tim

No comments:

Post a Comment