-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Wrap event and added delegates to handle event lifetime
- Loading branch information
Showing
7 changed files
with
132 additions
and
12 deletions.
There are no files selected for viewing
File renamed without changes.
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
51 changes: 51 additions & 0 deletions
51
src/Workleap.DomainEventPropagation.Subscription.PullDelivery/CloudEventHandler.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Azure.Messaging; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Workleap.DomainEventPropagation; | ||
|
||
internal class CloudEventHandler : ICloudEventHandler | ||
{ | ||
private readonly IDomainEventTypeRegistry _domainEventTypeRegistry; | ||
private readonly ILogger<CloudEventHandler> _logger; | ||
private readonly DomainEventHandlerDelegate _pipeline; | ||
|
||
public CloudEventHandler( | ||
IDomainEventTypeRegistry domainEventTypeRegistry, | ||
IEnumerable<IDomainEventBehavior> domainEventBehaviors, | ||
ILogger<CloudEventHandler> logger) | ||
{ | ||
this._domainEventTypeRegistry = domainEventTypeRegistry; | ||
this._logger = logger; | ||
this._pipeline = domainEventBehaviors.Reverse().Aggregate((DomainEventHandlerDelegate)HandleDomainEventAsync, BuildPipeline); | ||
} | ||
|
||
public async Task HandleEventGridWebhookEventAsync(CloudEvent cloudEvent, AcknowledgeEventDelegate acknowledge, ReleaseEventDelegate release, RejectEventDelegate reject, CancellationToken cancellationToken) | ||
{ | ||
var domainEventWrapper = new DomainEventWrapper(cloudEvent); | ||
|
||
var domainEventType = this._domainEventTypeRegistry.GetDomainEventType(domainEventWrapper.DomainEventName); | ||
if (domainEventType == null) | ||
{ | ||
this._logger.EventDomainTypeNotRegistered(domainEventWrapper.DomainEventName, cloudEvent.Subject ?? "Unknown"); | ||
return; | ||
} | ||
|
||
await this._pipeline(domainEventWrapper, acknowledge, release, reject, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
private static DomainEventHandlerDelegate BuildPipeline(DomainEventHandlerDelegate next, IDomainEventBehavior pipeline) | ||
{ | ||
return (@event, acknowledge, release, reject, cancellationToken) => pipeline.HandleAsync(@event, acknowledge, release, reject, next, cancellationToken); | ||
} | ||
|
||
private static Task HandleDomainEventAsync( | ||
DomainEventWrapper domainEventWrapper, | ||
AcknowledgeEventDelegate acknowledge, | ||
ReleaseEventDelegate release, | ||
RejectEventDelegate reject, | ||
CancellationToken cancellationToken) | ||
{ | ||
// Todo : Get event handler that matches wrapper type and invoke it | ||
return Task.CompletedTask; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/Workleap.DomainEventPropagation.Subscription.PullDelivery/ICloudEventHandler.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Azure.Messaging; | ||
|
||
namespace Workleap.DomainEventPropagation; | ||
|
||
internal delegate Task AcknowledgeEventDelegate(); | ||
|
||
internal delegate Task ReleaseEventDelegate(); | ||
|
||
internal delegate Task RejectEventDelegate(); | ||
|
||
internal interface ICloudEventHandler | ||
{ | ||
Task HandleEventGridWebhookEventAsync( | ||
CloudEvent cloudEvent, | ||
AcknowledgeEventDelegate acknowledge, | ||
ReleaseEventDelegate release, | ||
RejectEventDelegate reject, | ||
CancellationToken cancellationToken); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Workleap.DomainEventPropagation.Subscription.PullDelivery/IDomainEventBehavior.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Workleap.DomainEventPropagation; | ||
|
||
internal delegate Task DomainEventHandlerDelegate( | ||
DomainEventWrapper domainEventWrapper, | ||
AcknowledgeEventDelegate acknowledge, | ||
ReleaseEventDelegate release, | ||
RejectEventDelegate reject, | ||
CancellationToken cancellationToken); | ||
|
||
internal interface IDomainEventBehavior | ||
{ | ||
Task HandleAsync( | ||
DomainEventWrapper domainEventWrapper, | ||
AcknowledgeEventDelegate acknowledge, | ||
ReleaseEventDelegate release, | ||
RejectEventDelegate reject, | ||
DomainEventHandlerDelegate next, | ||
CancellationToken cancellationToken); | ||
} |
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