Search code examples
masstransit

The same response type in two requests in MassTransit Saga


I'm trying to create a state machine and I'd like to send multiple requests from this state machine. The requests are defined as follows:

public Request<StageState, ICloseStage, ICloseStageRequestSuccess, IRequestFailed> CloseStageRequest { get; private set; }

public Request<StageState, IPublishStage, IPublishStageRequestSuccess, IRequestFailed> PublishStageRequest { get; private set; }

Both requests might get the same response in Response2. However, when I'm running the state machine I'm getting the following error:

System.ArgumentException : An item with the same key has already been added. Key: IRequestFailed

So, I suppose this is happening because I'm using IRequestFailed in both requests. Is it a by-design behavior or is there a workaround so I can use this response type in both requests? I really need to use it in this way because IRequestFailed is processed in a unified way for all the requests in the state machine, and I'm planning to add more requests.

Thanks in advance.


Solution

  • The MassTransit state machine does not support two requests with the same response type.