1

I am trying to use the Masstransit library, implementing the mediator provided by Masstransit to communicate my controller layer with the application layer, and also adding the transactional outbox pattern, but executing my project, when I use the mediator, the context is different when using a simple service.

You can find the source code in this repo https://github.com/leojim06/masstransit-transactional-outbox

My question is, How can I use MassTransit mediator with MassTransit transactional outbox? My intention is to use the MassTransit mediator to communicate the controller layer with the application layer, the same as MediatR works. After that, need to save some information to the database and intercept the insert command with the published message (as the transactional outbox solves the inconsistency issues)

Do you have a different approach to achieving my requirement?

1 Answers1

0

You can't, the transactional outbox only works with durable transports.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • Are there any plans to make it work with the Mediator? – Oleksandr Kobylianskyi Mar 28 '23 at 08:27
  • No, not at all. – Chris Patterson Mar 28 '23 at 12:11
  • Does this mean that the MassTransit Mediator use case is not identical to MediatR? And it shouldn't be used just for structuring code into the handlers for queries and commands received from the Web API controllers layer as such usage changes the runtime behavior of MassTransit itself. – Oleksandr Kobylianskyi Mar 28 '23 at 12:57
  • MassTransit Mediator and MediatR fit the same use cases, and MediatR doesn't have an outbox either. You could use the in-memory outbox with mediator, but why? Seems like you're just working the machine to earn a pattern merit badge vs adding any real business value. – Chris Patterson Mar 28 '23 at 13:21
  • MediatR doesn't have it, and I don't expect it. Let's say I have an action triggered from UI via the Web API controller. This action involves updating the MSSQL database with Entity Framework and message publishing to RabbitMQ with MassTransit. To achieve reliable message publishing, I want to use `IPublishEndpoint` with Transactional Outbox configured (specifically Bus outbox). MassTransit Transactional Outbox works fine if I use the MediatR handler to process the whole command (EF database update + MassTransit message publish). But it doesn't if I want to replace MediatR with MT Mediator. – Oleksandr Kobylianskyi Mar 28 '23 at 14:19
  • 1
    It should work fine if you use `IScopedMediator` within the controller. – Chris Patterson Mar 28 '23 at 17:37