-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed custom IProjections like KafkaProducer, SignalRProducer, Elas…
…ticProjection to subscriptions
- Loading branch information
1 parent
935b79a
commit 5a8fc7a
Showing
15 changed files
with
247 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 22 additions & 16 deletions
38
Sample/Helpdesk.Wolverine/Helpdesk.Api/Core/SignalR/SignalRProducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
using Marten; | ||
using Marten.Events; | ||
using Marten.Events.Projections; | ||
using Marten.Events.Daemon; | ||
using Marten.Events.Daemon.Internals; | ||
using Marten.Subscriptions; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace Helpdesk.Api.Core.SignalR; | ||
|
||
public class SignalRProducer: IProjection | ||
public class SignalRProducer<THub>(IHubContext<THub> hubContext): SubscriptionBase where THub : Hub | ||
{ | ||
private readonly IHubContext hubContext; | ||
|
||
public SignalRProducer(IHubContext hubContext) => | ||
this.hubContext = hubContext; | ||
|
||
public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList<StreamAction> streamsActions, | ||
CancellationToken ct) | ||
public override async Task<IChangeListener> ProcessEventsAsync( | ||
EventRange eventRange, | ||
ISubscriptionController subscriptionController, | ||
IDocumentOperations operations, | ||
CancellationToken ct | ||
) | ||
{ | ||
foreach (var @event in streamsActions.SelectMany(streamAction => streamAction.Events)) | ||
foreach (var @event in eventRange.Events) | ||
{ | ||
await hubContext.Clients.All.SendAsync(@event.EventTypeName, @event.Data, ct); | ||
try | ||
{ | ||
await hubContext.Clients.All.SendAsync(@event.EventTypeName, @event.Data, ct); | ||
} | ||
catch (Exception exc) | ||
{ | ||
// this is fine to put event to dead letter queue, as it's just SignalR notification | ||
await subscriptionController.RecordDeadLetterEventAsync(@event, exc); | ||
} | ||
} | ||
} | ||
|
||
public void Apply(IDocumentOperations operations, IReadOnlyList<StreamAction> streams) => | ||
throw new NotImplementedException("Producer should be only used in the AsyncDaemon"); | ||
return NullChangeListener.Instance; | ||
} | ||
} | ||
|
Oops, something went wrong.