32 lines
849 B
C#
32 lines
849 B
C#
using System.Threading.Channels;
|
|
using Nexus.Api.Models;
|
|
|
|
namespace Nexus.Api.Services;
|
|
|
|
public interface IDomainEventStreamService
|
|
{
|
|
long CurrentSequence { get; }
|
|
|
|
DomainEventSubscription Subscribe(IReadOnlySet<string> channels);
|
|
}
|
|
|
|
public sealed class DomainEventSubscription(
|
|
ChannelReader<DomainEventDto> reader,
|
|
long startingSequence,
|
|
Func<ValueTask> disposeAsync) : IAsyncDisposable
|
|
{
|
|
public ChannelReader<DomainEventDto> Reader { get; } = reader;
|
|
public long StartingSequence { get; } = startingSequence;
|
|
|
|
public ValueTask DisposeAsync() => disposeAsync();
|
|
}
|
|
|
|
public sealed class DomainEventSubscriberOverflowException :
|
|
InvalidOperationException
|
|
{
|
|
public DomainEventSubscriberOverflowException()
|
|
: base("The domain-event subscriber queue overflowed and requires a REST resync.")
|
|
{
|
|
}
|
|
}
|