MassTransit saga states receiving unexpected events

26 views
Skip to first unread message

Diego Amaral

unread,
Aug 24, 2017, 3:34:25 PM8/24/17
to masstransit-discuss

 am using MassTransit.Automatonymous (version 3.3.5 ) to manage a saga and I seem to be receiving unexpected events after a state has transitioned.

Here is my state set up:


 Initially(
            When(Requested)
                .ThenAsync(InitialiseSaga)
                .TransitionTo(Initialising)
            );

        During(Initialising,
            When(InitialisationCompleted)
                .ThenAsync(FetchTraceSetMetaData)
                .TransitionTo(FetchingTraceSetMetaData)
            );

        During(FetchingTraceSetMetaData,
            When(TraceSetMetaDataRetrieved)
                .ThenAsync(ExtractTiffFiles)
                .TransitionTo(ExtractingTiffFiles)
            );

        During(ExtractingTiffFiles,
            When(TiffFilesExtracted)
                .ThenAsync(DispatchTiffParseMessages)
                .TransitionTo(DispatchingTiffParseMessages)
            );



I am using MassTransit.Automatonymous (version 3.3.5 ) to manage a saga and I seem to be receiving unexpected events after a state has transitioned.

Here is my state set up:

        Initially(
            When(Requested)
                .ThenAsync(InitialiseSaga)
                .TransitionTo(Initialising)
            );

        During(Initialising,
            When(InitialisationCompleted)
                .ThenAsync(FetchTraceSetMetaData)
                .TransitionTo(FetchingTraceSetMetaData)
            );

        During(FetchingTraceSetMetaData,
            When(TraceSetMetaDataRetrieved)
                .ThenAsync(ExtractTiffFiles)
                .TransitionTo(ExtractingTiffFiles)
            );

        During(ExtractingTiffFiles,
            When(TiffFilesExtracted)
                .ThenAsync(DispatchTiffParseMessages)
                .TransitionTo(DispatchingTiffParseMessages)
            );

The error I sometimes receive is:

The TraceSetMetaDataRetrieved event is not handled during the ExtractingTiffFiles state for the ImportTraceSetDataStateMachine state machine

My understanding of how this should work at the point of the error is as follows:

During the FetchingTraceSetMetaData state, at some point I'll receive a TraceSetMetaDataRetrieved event. When this occurs, run the ExtractTiffFiles method, and transition to the ExtractingTiffFiles state.

Once in the ExtractingTiffFiles state, I wouldn't expect the TraceSetMetaDataRetrieved event since it's what got us into the ExtractingTiffFiles state.

The two FetchTraceSetMetaData and ExtractTiffFiles methods are as follows (truncated for brevity):

public async Task FetchTraceSetMetaData(BehaviorContext<ImportTraceSetDataSagaState, InitialisationCompleteEvent> context)
    {
        var traceSetId = context.Instance.TraceSetId;
        _log.Information($"Getting pixel indicies for trace set with id {traceSetId}");

        // Snip...!

        await context.Publish(new TraceSetMetaDataRetrievedEvent { CorrelationId = context.Data.CorrelationId });
    }


    public async Task ExtractTiffFiles(BehaviorContext<ImportTraceSetDataSagaState, TraceSetMetaDataRetrievedEvent> context)
    {
        _log.Information($"Extracting tiffs for {context.Instance.TiffZipFileKey} and trace set with id {context.Instance.TraceSetId}");

        // Snip...!

        // Dispatch an event to put the saga in the next state where we dispatch the parse messages
        await context.Publish(new TiffFilesExtractedEvent { CorrelationId = context.Data.CorrelationId });
    }


Post posting pondering

It's just occurred to me that perhaps I should have my TransitionTo statements before my ThenAsync statements. e.g.

During(FetchingTraceSetMetaData,
        When(TraceSetMetaDataRetrieved)
            .TransitionTo(ExtractingTiffFiles)
            .ThenAsync(ExtractTiffFiles)
        );

Is that what I'm doing wrong?

Chris Patterson

unread,
Aug 28, 2017, 10:22:05 AM8/28/17
to masstrans...@googlegroups.com
Which saga repository are you using? It's likely that you are seeing the event processed before the previous one has completed (messages deliver quickly). Particularly since it appears you're doing the actual extraction of the files in the saga itself. So the work is already done, and you're producing the event, which is consumed in a separate thread.

You could setup a delayed retry so that it will try to process the event again after a brief timeout, that's an option.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/25f91d90-dace-43aa-9722-94bed9748863%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages