Skip to content

Commit 636289e

Browse files
committed
feat(outbox): remove InMemory provider and update delivery options
- Eliminates the InMemory outbox provider to simplify the architecture. - Updates outbox delivery options to accept null for delivery and transaction commit timeouts. - Adjusts outbox delivery implementation to use a default provider instead of the removed InMemory provider. - Renames and moves related tests to maintain clarity and functionality.
1 parent da5fc62 commit 636289e

13 files changed

Lines changed: 36 additions & 209 deletions

File tree

ES.FX.slnx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<Project Path="src/ES.FX.Migrations/ES.FX.Migrations.csproj" />
1010
<Project Path="src/ES.FX.TransactionalOutbox.EntityFrameworkCore.SqlServer/ES.FX.TransactionalOutbox.EntityFrameworkCore.SqlServer.csproj" />
1111
<Project Path="src/ES.FX.TransactionalOutbox.EntityFrameworkCore.PostgreSql/ES.FX.TransactionalOutbox.EntityFrameworkCore.PostgreSql.csproj" />
12-
<Project Path="src/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory.csproj" />
1312
<Project Path="src/ES.FX.TransactionalOutbox.EntityFrameworkCore.MySql/ES.FX.TransactionalOutbox.EntityFrameworkCore.MySql.csproj" />
1413
<Project Path="src/ES.FX.TransactionalOutbox.EntityFrameworkCore/ES.FX.TransactionalOutbox.EntityFrameworkCore.csproj" />
1514
<Project Path="src/ES.FX.TransactionalOutbox.MassTransit/ES.FX.TransactionalOutbox.MassTransit.csproj" Id="513497bb-2cd5-49e5-84a3-98bd5eea6f42" />
@@ -84,7 +83,6 @@
8483
<Project Path="tests/ES.FX.Tests/ES.FX.Tests.csproj" />
8584
<Project Path="tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.SqlServer.Tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.SqlServer.Tests.csproj" />
8685
<Project Path="tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.PostgreSql.Tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.PostgreSql.Tests.csproj" />
87-
<Project Path="tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory.Tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory.Tests.csproj" />
8886
<Project Path="tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.MySql.Tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.MySql.Tests.csproj" />
8987
<Project Path="tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.Tests/ES.FX.TransactionalOutbox.EntityFrameworkCore.Tests.csproj" />
9088
</Folder>

src/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory.csproj

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory/InMemoryOutboxExtensions.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/ES.FX.TransactionalOutbox.EntityFrameworkCore.InMemory/InMemoryOutboxProvider.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/ES.FX.TransactionalOutbox.EntityFrameworkCore/Delivery/DefaultOutboxProvider.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ namespace ES.FX.TransactionalOutbox.EntityFrameworkCore.Delivery;
1212
public class DefaultOutboxProvider<TDbContext> : IOutboxProvider<TDbContext>
1313
where TDbContext : DbContext
1414
{
15-
public Task<Outbox?> GetNextExclusiveOutboxWithoutDelay(TDbContext dbContext,
15+
public async Task<Outbox?> GetNextExclusiveOutboxWithoutDelay(TDbContext dbContext,
1616
CancellationToken cancellationToken = default)
1717
{
18-
return dbContext.Set<Outbox>()
18+
return await dbContext.Set<Outbox>()
1919
.Where(o => o.Lock == null &&
2020
(o.DeliveryDelayedUntil == null || o.DeliveryDelayedUntil < DateTimeOffset.UtcNow))
2121
.OrderBy(o => o.AddedAt)
22-
.FirstOrDefaultAsync(cancellationToken);
22+
.AsTracking()
23+
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
2324
}
2425
}

src/ES.FX.TransactionalOutbox.EntityFrameworkCore/Delivery/OutboxDeliveryOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public abstract class OutboxDeliveryOptions
1818
/// The timeout for the delivery of a batch. This includes acquiring the outbox, processing the messages and releasing
1919
/// the lock.
2020
/// </summary>
21-
public TimeSpan DeliveryTimeout { get; set; } = TimeSpan.FromSeconds(5);
21+
public TimeSpan? DeliveryTimeout { get; set; }
22+
23+
24+
/// <summary>
25+
/// The timeout used to commit changes after processing a batch of messages.
26+
/// </summary>
27+
public TimeSpan? TransactionCommitTimeout { get; set; }
2228

2329

2430
/// <summary>

src/ES.FX.TransactionalOutbox.EntityFrameworkCore/Delivery/OutboxDeliveryService.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
9696
try
9797
{
9898
using var handlerReadyTimeout = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken,
99-
new CancellationTokenSource(outboxDeliveryOptions.DeliveryTimeout).Token);
99+
outboxDeliveryOptions.DeliveryTimeout.HasValue
100+
? new CancellationTokenSource(outboxDeliveryOptions.DeliveryTimeout.Value).Token
101+
: CancellationToken.None);
100102
messageHandlerReady =
101103
await messageHandler.IsReadyAsync(handlerReadyTimeout.Token).ConfigureAwait(false);
102104
}
@@ -128,7 +130,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
128130
await dbContext.Database.CreateExecutionStrategy().ExecuteAsync(async () =>
129131
{
130132
using var deliveryTimeout = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken,
131-
new CancellationTokenSource(outboxDeliveryOptions.DeliveryTimeout).Token);
133+
outboxDeliveryOptions.DeliveryTimeout.HasValue
134+
? new CancellationTokenSource(outboxDeliveryOptions.DeliveryTimeout.Value).Token
135+
: CancellationToken.None);
132136

133137

134138
await using var transaction = await dbContext.Database
@@ -295,8 +299,14 @@ await DeliverMessage(message, messageContext, messageHandler, deliveryTimeout.To
295299

296300
try
297301
{
298-
await dbContext.SaveChangesAsync(deliveryTimeout.Token).ConfigureAwait(false);
299-
await transaction.CommitAsync(deliveryTimeout.Token).ConfigureAwait(false);
302+
using var commitTimeout = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken,
303+
outboxDeliveryOptions.TransactionCommitTimeout.HasValue
304+
? new CancellationTokenSource(outboxDeliveryOptions.TransactionCommitTimeout
305+
.Value).Token
306+
: CancellationToken.None);
307+
308+
await dbContext.SaveChangesAsync(commitTimeout.Token).ConfigureAwait(false);
309+
await transaction.CommitAsync(commitTimeout.Token).ConfigureAwait(false);
300310
}
301311
catch (Exception exception)
302312
{

src/ES.FX.TransactionalOutbox.EntityFrameworkCore/ES.FX.TransactionalOutbox.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
<ItemGroup>
24-
<Folder Include="Extensions\" />
24+
<Folder Include="Extensions\" />
2525
</ItemGroup>
2626

2727
</Project>

tests/ES.FX.Shared.Redis.Tests/RedisFixtureTests.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/ES.FX.Shared.SqlServer.Tests/SqlServerFixtureTests.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)