From 56fee09e1df26c14fef151e17e5d78c16cd0f34f Mon Sep 17 00:00:00 2001 From: MnatsakanMargaryan Date: Thu, 20 Nov 2025 17:57:26 +0400 Subject: [PATCH] Improve exception handling in InboxConsumer Updated the `InboxConsumer` class to use `ExecuteUpdateAsync` for atomic updates to the `UpdatedAt` field, ensuring better concurrency handling. Added a `throw` statement after rollback to propagate exceptions properly. Bumped the project version in `MassTransit.PostgresOutbox.csproj` from `3.0.2` to `3.0.3` to reflect these changes. --- .../Abstractions/InboxConsumer.cs | 8 +++++--- .../MassTransit.PostgresOutbox.csproj | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/MassTransit.PostgresOutbox/Abstractions/InboxConsumer.cs b/src/MassTransit.PostgresOutbox/Abstractions/InboxConsumer.cs index 2bf0fc6..c74dee3 100644 --- a/src/MassTransit.PostgresOutbox/Abstractions/InboxConsumer.cs +++ b/src/MassTransit.PostgresOutbox/Abstractions/InboxConsumer.cs @@ -75,11 +75,13 @@ public async Task Consume(ConsumeContext context) logger.LogError(ex, "Exception thrown while consuming message {messageId} by {consumerId}", messageId, _consumerId); - + await transactionScope.RollbackAsync(); - inboxMessage.UpdatedAt = DateTime.UtcNow; - await dbContext.SaveChangesAsync(); + await dbContext.InboxMessages + .Where(x => x.MessageId == messageId && x.ConsumerId == _consumerId) + .ExecuteUpdateAsync(x => x.SetProperty(x => x.UpdatedAt, x => DateTime.UtcNow)); + throw; } } diff --git a/src/MassTransit.PostgresOutbox/MassTransit.PostgresOutbox.csproj b/src/MassTransit.PostgresOutbox/MassTransit.PostgresOutbox.csproj index c5d51ab..6e0d895 100644 --- a/src/MassTransit.PostgresOutbox/MassTransit.PostgresOutbox.csproj +++ b/src/MassTransit.PostgresOutbox/MassTransit.PostgresOutbox.csproj @@ -8,7 +8,7 @@ Readme.md Pandatech MIT - 3.0.2 + 3.0.3 Pandatech.MassTransit.PostgresOutbox Pandatech MassTransit PostgreSQL Outbox Extension Pandatech, library, postgres, distributed systems, microservices, modular monolith, messaging, efcore, mass transit, outbox pattern, inbox pattern