Im using MassTransit Sagas. It starts when an incoming event(AccountCreatedInWebAppEvent) does some processing and will then publish another event (SagaAccountCreatedEvent)
I have a consumer that listens to SagaAccountCreatedEvent, but in the consumer the context.CorrelationId is null if I dont set it explicitly as in the example below (return new SagaAccountCreatedEvent() {...}). Shoulnt the correlationId be included without me having to insert it into the message, by the Saga-magic? (the same goes for publishing from a consumer to Saga-"handler")
InstanceState(i => i.CurrentState);
Event(() => AccountCreatedInWebAppEvent, e => e.CorrelateBy<int>(sagaState => sagaState.AccountId, context => context.Message.Account.AccountId)
.SelectId(context => Guid.NewGuid()))
...
Initially(
When(AccountCreatedInWebAppEvent)
.Then(context =>
{
context.Instance.AccountId = context.Data.Account.AccountId;
context.Instance.CreatedInWebApp = DateTime.Now;
})
.TransitionTo(AccountCreatedSentOut)
.Publish(context =>
{
return new SagaAccountCreatedEvent() { Account = context.Data.Account, CorrelationId = context.CorrelationId.Value };
})
Consumer method
public async Task Consume(ConsumeContext context) {
//here context.correlationId is null
}