public AllStreamSubscription( long?continueAfterPosition, IReadonlyStreamStore readonlyStreamStore, IObservable <Unit> streamStoreAppendedNotification, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name) { FromPosition = continueAfterPosition; LastPosition = continueAfterPosition; _nextPosition = continueAfterPosition + 1 ?? Position.Start; _readonlyStreamStore = readonlyStreamStore; _streamMessageReceived = streamMessageReceived; _prefetchJsonData = prefetchJsonData; _subscriptionDropped = subscriptionDropped ?? ((_, __, ___) => { }); _hasCaughtUp = hasCaughtUp ?? (_ => { }); Name = string.IsNullOrWhiteSpace(name) ? Guid.NewGuid().ToString() : name; readonlyStreamStore.OnDispose += ReadonlyStreamStoreOnOnDispose; _notification = streamStoreAppendedNotification.Subscribe(_ => { _streamStoreNotification.Set(); }); Task.Run(PullAndPush); s_logger.Info( "AllStream subscription created {name} continuing after position {position}", Name, continueAfterPosition?.ToString() ?? "<null>"); }
protected abstract IAllStreamSubscription SubscribeToAllInternal( long?fromPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name);
protected abstract IStreamSubscription SubscribeToStreamInternal( string streamId, int?startVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, string name);
public StreamSubscription( string streamId, int?continueAfterVersion, IReadonlyStreamStore readonlyStreamStore, IObservable <Unit> streamStoreAppendedNotification, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefectchJsonData, string name) { StreamId = streamId; _continueAfterVersion = continueAfterVersion; _readonlyStreamStore = readonlyStreamStore; _streamMessageReceived = streamMessageReceived; _prefectchJsonData = prefectchJsonData; _subscriptionDropped = subscriptionDropped ?? ((_, __, ___) => { }); _hasCaughtUp = hasCaughtUp ?? ((_) => { }); Name = string.IsNullOrWhiteSpace(name) ? Guid.NewGuid().ToString() : name; readonlyStreamStore.OnDispose += ReadonlyStreamStoreOnOnDispose; _notification = streamStoreAppendedNotification.Subscribe(_ => { _streamStoreNotification.Set(); }); Task.Run(PullAndPush); s_logger.Info($"Stream subscription created {Name} continuing after version " + $"{continueAfterVersion?.ToString() ?? "<null>"}."); }
private void SubscribeToAll( long?start = null, HasCaughtUp hasCaughtUp = null, bool testing = false) { _store.SubscribeToAll(start, StreamMessageReceived, SubscriptionDropped, hasCaughtUp); }
protected override IAllStreamSubscription SubscribeToAllInternal( long?fromPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, string name) { throw new NotImplementedException(); }
protected override IStreamSubscription SubscribeToStreamInternal( string streamId, int?startVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, string name) { throw new NotImplementedException(); }
private Task <IDisposable> CreateSubscription( AllStreamPosition fromPosition, MessageReceived onMessage, HasCaughtUp hasCaughtUp, Func <Exception, Task> onSubscriptionError) => Task.FromResult <IDisposable>(new GenericSubscription( (from, ct) => EventStore.ReadForward(from, cancellationToken: ct), fromPosition, Notifier.WaitForNotification, onMessage, onSubscriptionError, hasCaughtUp));
/// <summary> /// Subscribes to latest changes. /// Only supports a single subscriber at a time, based on notifier implementation. /// </summary> public Task <IDisposable> Subscribe( AllStreamPosition fromPosition, MessageReceived onMessage, HasCaughtUp hasCaughtUp, Func <Exception, Task> onSubscriptionError) => Task.FromResult <IDisposable>( new GenericSubscription( (f, ct) => ReadForward(f, 10, ct), fromPosition, _notifier.WaitForNotification, onMessage, onSubscriptionError, hasCaughtUp));
public SubscriptionFixture(Action <string> writeLine, long maxPosition = 20, long handlerExceptionPosition = -2) { _writeLine = writeLine; _cts = new CancellationTokenSource(); MaxPosition = maxPosition; AllStreamPosition hasCaughtUpTrigger = AllStreamPosition.None; AllStreamPosition notifierTrigger = AllStreamPosition.None; ReadAllPageFunc readAllPage = (from, ct) => Task.FromResult(Read(from)); MessageReceived handler = (s, m, ct) => { LastProcessed = m.Checkpoint; if (m.Checkpoint == handlerExceptionPosition) { throw new InvalidOperationException("Custom exception thrown"); } return(Task.CompletedTask); }; Func <Exception, Task> onError = ex => Async(() => _exceptionSource.SetResult(ex)); HasCaughtUp hasCaughtUp = () => Async(() => hasCaughtUpTrigger = hasCaughtUpTrigger.Shift()); var hasCaughtUpNotifier = new PollingNotifier(_ => Task.FromResult(hasCaughtUpTrigger)); var notifier = new PollingNotifier(_ => Task.FromResult(notifierTrigger)); Subscription = new GenericSubscription( readAllPage, AllStreamPosition.None, notifier.WaitForNotification, handler, onError, hasCaughtUp); var cancellationToken = _cts.Token; cancellationToken.Register(() => { Subscription.Dispose(); notifier.Dispose(); hasCaughtUpNotifier.Dispose(); }); WaitForCaughtUp = () => hasCaughtUpNotifier.WaitForNotification(cancellationToken); AppendEvents = c => { MaxPosition += c; notifierTrigger = notifierTrigger.Shift(); }; }
public IAllStreamSubscription SubscribeToAll( long?continueAfterPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, bool prefetchJsonData = true, string name = null) => new AllStreamSubscription( continueAfterPosition, this, _streamStoreNotifier.Value, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name);
protected override IAllStreamSubscription SubscribeToAllInternal( long?fromPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name) => new AllStreamSubscription( fromPosition, this, GetStoreObservable, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name);
protected override IAllStreamSubscription SubscribeToAllInternal( long?fromPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, string name) { return(new AllStreamSubscription( fromPosition, this, GetStoreObservable, streamMessageReceived, subscriptionDropped, hasCaughtUp, name)); }
public IAllStreamSubscription SubscribeToAll( long?continueAfterPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, bool prefetchJsonData = true, string name = null) { return(_streamStore .SubscribeToAll( continueAfterPosition, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name)); }
protected override IStreamSubscription SubscribeToStreamInternal( string streamId, int?startVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name) => new StreamSubscription( streamId, startVersion, this, GetStoreObservable, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name);
public IAllStreamSubscription SubscribeToAll( long?continueAfterPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, string name = null) { Ensure.That(streamMessageReceived, nameof(streamMessageReceived)).IsNotNull(); GuardAgainstDisposed(); return(SubscribeToAllInternal(continueAfterPosition, streamMessageReceived, subscriptionDropped, hasCaughtUp, name)); }
protected override IAllStreamSubscription SubscribeToAllInternal( long?fromPosition, AllStreamMessageReceived streamMessageReceived, AllSubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name) { return(new AllStreamSubscription( fromPosition, this, _subscriptions, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name)); }
public IStreamSubscription SubscribeToStream( StreamId streamId, int?continueAfterVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, bool prefetchJsonData = true, string name = null) => new StreamSubscription( streamId, continueAfterVersion, this, _streamStoreNotifier.Value, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name);
protected override IStreamSubscription SubscribeToStreamInternal( string streamId, int?startVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, string name) { return(new StreamSubscription( streamId, startVersion, this, GetStoreObservable, streamMessageReceived, subscriptionDropped, hasCaughtUp, name)); }
public GenericSubscription( ReadAllPageFunc readAllPage, AllStreamPosition fromPosition, Func <CancellationToken, Task> waitForEvent, MessageReceived onMessage, Func <Exception, Task> onSubscriptionError, HasCaughtUp hasCaughtUp) { _readAllPage = readAllPage; FromPosition = fromPosition; _nextPosition = new AllStreamPosition(fromPosition.ToNullableInt64() + 1 ?? 0); _waitForEvent = waitForEvent; _onMessage = onMessage; _hasCaughtUp = hasCaughtUp ?? (() => Task.CompletedTask); _onSubscriptionError = onSubscriptionError ?? (_ => Task.CompletedTask); LastPosition = fromPosition; Task.Run(PullAndPush); }
public IStreamSubscription SubscribeToStream( StreamId streamId, int?continueAfterVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, bool prefetchJsonData = true, string name = null) { return(_streamStore .SubscribeToStream( streamId, continueAfterVersion, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name)); }
protected override IStreamSubscription SubscribeToStreamInternal( string streamId, int?startVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped, HasCaughtUp hasCaughtUp, bool prefetchJsonData, string name) { return(new StreamSubscription( streamId, startVersion, this, _subscriptions, streamMessageReceived, subscriptionDropped, hasCaughtUp, prefetchJsonData, name)); }
public IStreamSubscription SubscribeToStream( string streamId, int?continueAfterVersion, StreamMessageReceived streamMessageReceived, SubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, string name = null) { Ensure.That(streamId, nameof(streamId)).IsNotNullOrWhiteSpace(); Ensure.That(streamMessageReceived, nameof(streamMessageReceived)).IsNotNull(); GuardAgainstDisposed(); return(SubscribeToStreamInternal( streamId, continueAfterVersion, streamMessageReceived, subscriptionDropped, hasCaughtUp, name)); }