Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to ensure message reception order in MassTransit
    text
    copied!<p>I have a saga that has 3 states; Initial, ReceivingRows, Completed -</p> <pre><code> public static State Initial { get; set; } public static State ReceivingRows { get; set; } public static State Completed { get; set; } </code></pre> <p>It transitions from Initial to ReceivingRows when it gets a BofMessage (where Bof = Beginning of file). After the BofMessage, it receives a large number of RowMessages where each describes a row in a flat file. Once all RowMessages are sent, an EofMessage is sent and the state changes to Completed. Observe -</p> <pre><code> static void DefineSagaBehavior() { Initially(When(ReceivedBof) .Then((saga, message) =&gt; saga.BeginFile(message)) .TransitionTo(ReceivingRows)); During(ReceivingRows, When(ReceivedRow) .Then((saga, message) =&gt; saga.AddRow(message))); During(ReceivingRows, When(ReceivedRowError) .Then((saga, message) =&gt; saga.RowError(message))); During(ReceivingRows, When(ReceivedEof) .Then((saga, message) =&gt; saga.EndFile(message)) .TransitionTo(Completed)); } </code></pre> <p>This works, except sometimes several RowMessages are received <em>before</em> the BofMessage! This is regardless of the order that I sent them. This means that the messages will be received and ultimately counted as errors, causing them to be missing from the database or file that I finally write them out to.</p> <p>As a temporary fix, I add a little sleep timer hack in this method that does all the publishing –</p> <pre><code> public static void Publish( [NotNull] IServiceBus serviceBus, [NotNull] string publisherName, Guid correlationId, [NotNull] Tuple&lt;string, string&gt; inputFileDescriptor, [NotNull] string outputFileName) { // attempt to load offsets var offsetsResult = OffsetParser.Parse(inputFileDescriptor.Item1); if (offsetsResult.Result != ParseOffsetsResult.Success) { // publish an offsets invalid message serviceBus.Publish&lt;TErrorMessage&gt;(CombGuid.Generate(), publisherName, inputFileDescriptor.Item2); return; } // publish beginning of file var fullInputFilePath = Path.GetFullPath(inputFileDescriptor.Item2); serviceBus.Publish&lt;TBofMessage&gt;(correlationId, publisherName, fullInputFilePath); // HACK: make sure bof message happens before row messages, or else some row messages won't be received Thread.Sleep(5000); // publish rows from feed var feedResult = FeedParser.Parse(inputFileDescriptor.Item2, offsetsResult.Offsets); foreach (var row in feedResult) { // publish row message, unaligned if applicable if (row.Result != ParseRowResult.Success) serviceBus.Publish&lt;TRowErrorMessage&gt;(correlationId, publisherName, row.Fields); else serviceBus.Publish&lt;TRowMessage&gt;(correlationId, publisherName, row.Fields); } // publish end of file serviceBus.Publish&lt;TEofMessage&gt;(correlationId, publisherName, outputFileName); } </code></pre> <p>It’s a 5 second sleep-timer, and is quite an ugly hack. Can anyone inform me why I’m not getting the messages in the order I send them? Can I ensure that these message get sent in the right order if they are unordered by default?</p> <p>Thank you!</p> <p><strong>Please note this is cross-posted from <a href="http://groups.google.com/group/masstransit-discuss/browse_thread/thread/7bd9518a690db4bb" rel="nofollow">http://groups.google.com/group/masstransit-discuss/browse_thread/thread/7bd9518a690db4bb</a> for expedience.</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload