-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Message Bus Consumers + OutBox Event Publishers
- Loading branch information
1 parent
574549a
commit 9dbc98c
Showing
41 changed files
with
1,130 additions
and
388 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
9 changes: 9 additions & 0 deletions
9
...services/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/IMessageBusConsumer.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,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Domain.Infrastructure.MessageBrokers; | ||
|
||
public interface IMessageBusConsumer<TConsumer, T> | ||
{ | ||
Task HandleAsync(T data, MetaData metaData, CancellationToken cancellationToken = default); | ||
} |
24 changes: 24 additions & 0 deletions
24
...rvices/Common/ClassifiedAds.Domain/Infrastructure/MessageBrokers/IOutBoxEventPublisher.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,24 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Domain.Infrastructure.MessageBrokers; | ||
|
||
public interface IOutBoxEventPublisher | ||
{ | ||
static abstract string[] CanHandleEventTypes(); | ||
|
||
static abstract string CanHandleEventSource(); | ||
|
||
Task HandleAsync(PublishingOutBoxEvent outbox, CancellationToken cancellationToken = default); | ||
} | ||
|
||
public class PublishingOutBoxEvent | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string EventType { get; set; } | ||
|
||
public string EventSource { get; set; } | ||
|
||
public string Payload { get; set; } | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...Common/ClassifiedAds.Infrastructure/HostedServices/MessageBusConsumerBackgroundService.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,27 @@ | ||
using ClassifiedAds.Domain.Infrastructure.MessageBrokers; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Infrastructure.HostedServices; | ||
|
||
public sealed class MessageBusConsumerBackgroundService<TConsumer, T> : BackgroundService | ||
where T : IMessageBusEvent | ||
{ | ||
private readonly ILogger<MessageBusConsumerBackgroundService<TConsumer, T>> _logger; | ||
private readonly IMessageBus _messageBus; | ||
|
||
public MessageBusConsumerBackgroundService(ILogger<MessageBusConsumerBackgroundService<TConsumer, T>> logger, | ||
IMessageBus messageBus) | ||
{ | ||
_logger = logger; | ||
_messageBus = messageBus; | ||
} | ||
|
||
protected override Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
_messageBus.ReceiveAsync<TConsumer, T>(stoppingToken); | ||
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
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
Oops, something went wrong.