コード例 #1
0
        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>");
        }
コード例 #2
0
 protected abstract IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     bool prefetchJsonData,
     string name);
コード例 #3
0
 protected abstract IStreamSubscription SubscribeToStreamInternal(
     string streamId,
     int?startVersion,
     StreamMessageReceived streamMessageReceived,
     SubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name);
コード例 #4
0
        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>"}.");
        }
コード例 #5
0
 private void SubscribeToAll(
     long?start = null,
     HasCaughtUp hasCaughtUp = null,
     bool testing            = false)
 {
     _store.SubscribeToAll(start, StreamMessageReceived,
                           SubscriptionDropped, hasCaughtUp);
 }
コード例 #6
0
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 protected override IStreamSubscription SubscribeToStreamInternal(
     string streamId,
     int?startVersion,
     StreamMessageReceived streamMessageReceived,
     SubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 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));
コード例 #9
0
 /// <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));
コード例 #10
0
        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();
            };
        }
コード例 #11
0
 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);
コード例 #12
0
 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);
コード例 #13
0
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name)
 {
     return(new AllStreamSubscription(
                fromPosition,
                this,
                GetStoreObservable,
                streamMessageReceived,
                subscriptionDropped,
                hasCaughtUp,
                name));
 }
コード例 #14
0
 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));
 }
コード例 #15
0
 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);
コード例 #16
0
        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));
        }
コード例 #17
0
 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));
 }
コード例 #18
0
 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);
コード例 #19
0
 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));
 }
コード例 #20
0
        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);
        }
コード例 #21
0
 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));
 }
コード例 #22
0
 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));
 }
コード例 #23
0
        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));
        }