Skip to content

Commit b732acc

Browse files
committed
exception receiver
1 parent 81e83ac commit b732acc

6 files changed

+29
-57
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,5 @@ healthchecksdb
347347

348348
# Backup folder for Package Reference Convert tool in Visual Studio 2017
349349
MigrationBackup/
350+
351+
event-queue-sandbox.sln

Client/ErrorReceiver.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using FastEndpoints;
2+
using MongoDB.Entities;
3+
4+
namespace SubscriberClient;
5+
6+
internal sealed class ErrorReceiver : SubscriberExceptionReceiver
7+
{
8+
private readonly DbContext db;
9+
10+
public ErrorReceiver(DbContext dbContext, ILogger<ErrorReceiver> logger)
11+
{
12+
db = dbContext;
13+
logger.LogInformation("Subscriber Error Receiver Initialized!");
14+
}
15+
16+
public override async Task OnMarkEventAsCompleteError<TEvent>(IEventStorageRecord record, int attemptCount, Exception exception, CancellationToken ct)
17+
{
18+
var r = (EventRecord)record;
19+
r.IsComplete = true;
20+
await r.SaveAsync();
21+
}
22+
}

Client/Program.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
var bld = WebApplication.CreateBuilder();
66
bld.Services.AddSingleton(new DbContext("SubscriberEventStore", "localhost"));
7+
//bld.Services.AddSubscriberExceptionReceiver<ErrorReceiver>();
78

89
var app = bld.Build();
910

Client/SubscriberStorageProvider.cs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public async ValueTask StoreEventAsync(IEventStorageRecord e, CancellationToken
2929

3030
public async ValueTask MarkEventAsCompleteAsync(IEventStorageRecord e, CancellationToken ct)
3131
{
32+
//throw new InvalidOperationException("testing exception receiver!");
33+
3234
await db
3335
.Update<EventRecord>()
3436
.MatchID(((EventRecord)e).ID)

Server/PublisherServer.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="MongoDB.Entities" Version="22.0.0" />
12-
<PackageReference Include="FastEndpoints.Messaging.Remote" Version="5.*" />
11+
<PackageReference Include="MongoDB.Entities" Version="22.0.0" />
12+
<PackageReference Include="FastEndpoints.Messaging.Remote" Version="5.*" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

sandbox.sln

-55
This file was deleted.

0 commit comments

Comments
 (0)