Skip to content

Commit 56fee09

Browse files
MnatsakanMargaryanMnatsakanMargaryan
authored andcommitted
Improve exception handling in InboxConsumer
Updated the `InboxConsumer<TMessage, TDbContext>` 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.
1 parent 842d1e5 commit 56fee09

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/MassTransit.PostgresOutbox/Abstractions/InboxConsumer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ public async Task Consume(ConsumeContext<TMessage> context)
7575
logger.LogError(ex, "Exception thrown while consuming message {messageId} by {consumerId}",
7676
messageId,
7777
_consumerId);
78-
78+
7979
await transactionScope.RollbackAsync();
8080

81-
inboxMessage.UpdatedAt = DateTime.UtcNow;
82-
await dbContext.SaveChangesAsync();
81+
await dbContext.InboxMessages
82+
.Where(x => x.MessageId == messageId && x.ConsumerId == _consumerId)
83+
.ExecuteUpdateAsync(x => x.SetProperty(x => x.UpdatedAt, x => DateTime.UtcNow));
84+
8385
throw;
8486
}
8587
}

src/MassTransit.PostgresOutbox/MassTransit.PostgresOutbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>3.0.2</Version>
11+
<Version>3.0.3</Version>
1212
<PackageId>Pandatech.MassTransit.PostgresOutbox</PackageId>
1313
<Title>Pandatech MassTransit PostgreSQL Outbox Extension</Title>
1414
<PackageTags>Pandatech, library, postgres, distributed systems, microservices, modular monolith, messaging, efcore, mass transit, outbox pattern, inbox pattern</PackageTags>

0 commit comments

Comments
 (0)