asp.net-coremasstransitoutbox-pattern

How to get MassTransit ConversationId inside Asp.net core controller without sending any messages?


Inside an ASP.NET Core controller I have an action that creates messages and modifies the DB. In order to do it more reliable it uses the outbox pattern we implemented to serialize the messages to DB.

The problem is we lose the ConversationId of the messages from MassTransit when it is saved to DB, I did not find a way to get it out of the IPublishEndpoint interface.

Any suggestions how to get the ConversationId?

The messages are just any c# classes without any special interface.


Solution

  • The identifiers are initialized as part of the PublishContext<T>, so you'd need to ensure that all the properties, including the header collection, are properly serialized and replaced when the message is ultimately published.