protected override void Context()
        {
            for (int c = 1; c <= ParallelWriters; c++)
            {
                var client = new AcceptanceTestMongoPersistenceFactory().Build();

                if (c == 1)
                {
                    client.Drop();
                }
                client.Initialize();
                _writers.Add(client);
            }

            _observer = new Observer();

            var reader = new AcceptanceTestMongoPersistenceFactory().Build();

            _client = new PollingClient2(reader, c =>
            {
                _observer.OnNext(c);
                return(PollingClient2.HandlingResult.MoveToNext);
            }, PollingInterval);

            _client.StartFrom(0);
        }
Example #2
0
        private static void Main()
        {
            using (var store = WireupEventStore())
            {
                // append some commits to the EventStore
                AppendToStream(store, "Stream1");
                AppendToStream(store, "Stream2");
                AppendToStream(store, "Stream1");

                // now test the polling client
                Int64 checkpointToken = LoadCheckpoint();
                var   client          = new PollingClient2(store.Advanced, commit =>
                {
                    // Project the commit etc
                    Console.WriteLine(Resources.CommitInfo, commit.BucketId, commit.StreamId, commit.CommitSequence);
                    // Track the most recent checkpoint
                    checkpointToken = commit.CheckpointToken;
                    return(PollingClient2.HandlingResult.MoveToNext);
                },
                                                           waitInterval: 3000);

                client.StartFrom(checkpointToken);

                Console.WriteLine(Resources.PressAnyKey);
                Console.ReadKey();
                client.Stop();
                SaveCheckpoint(checkpointToken);
            }
        }
        public async Task Receive(
            Action <IEvent, IReceptionContext> onReceived,
            CancellationToken cancellation,
            ICheckpoint checkpoint)
        {
            var cancelling = new TaskCompletionSource <object>();

            cancellation.Register(() => cancelling.SetResult(null));
            using (var pollingClient = new PollingClient2(_eventStore.Advanced, OnCommitReceived))
            {
                pollingClient.StartFrom((long?)checkpoint ?? 0);
                await cancelling.Task;
            }

            PollingClient2.HandlingResult OnCommitReceived(ICommit commit)
            {
                var visibilityDate = DateTime.UtcNow - _receptionDelay;

                if (commit.CommitStamp > visibilityDate)
                {
                    return(PollingClient2.HandlingResult.Retry); // Wait more for the guaranteed reception delay
                }
                foreach (var evt in commit.Events)
                {
                    onReceived(evt.Body, commit);
                }

                return(PollingClient2.HandlingResult.MoveToNext);
            }
        }
Example #4
0
        public PollingClientRx(IPersistStreams persistStreams, int pollingInterval = 1000, CancellationToken cancellationToken = default)
        {
            if (persistStreams == null)
            {
                throw new ArgumentNullException(nameof(persistStreams));
            }
            if (pollingInterval <= 0)
            {
                throw new ArgumentException("Must be greater than 0", nameof(pollingInterval));
            }

            _subject        = new Subject <ICommit>();
            _pollingClient2 = new PollingClient2(persistStreams, c =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    _subject.OnCompleted();
                    return(PollingClient2.HandlingResult.Stop);
                }

                _subject.OnNext(c);
                return(PollingClient2.HandlingResult.MoveToNext);
            },
                                                 waitInterval: pollingInterval);
        }
        public async Task StartAsync(CancellationToken cancellationToken = default)
        {
            _currentCheckpoint = await _checkpointLoader.LoadAsync <long>().ConfigureAwait(false);

            _eventStore    = _serviceProvider.GetRequiredService <IStoreEvents>();
            _pollingClient = new PollingClient2(
                _eventStore.Advanced,
                c => cancellationToken.IsCancellationRequested ? PollingClient2.HandlingResult.Stop : CommitHandler(c));
            _pollingClient.StartFrom(_currentCheckpoint);
            _logger.LogInformation($"Starting event subscription from checkpoint {_currentCheckpoint}");
        }
        private void Init(Int64 checkpointTokenFrom, int intervalInMilliseconds, Int64 checkpointTokenSequenced, int bufferSize, string pollerName)
        {
            _bufferSize             = bufferSize;
            _checkpointTokenCurrent = checkpointTokenFrom;
            LastException           = null;
            //prepare single poller thread.
            CreateTplChain();

            _sequencer   = new CommitSequencer(DispatchCommit, _checkpointTokenCurrent, 2000);
            _innerClient = new PollingClient2(
                _persistStream,
                c =>
            {
                if (c.CheckpointToken <= checkpointTokenSequenced)
                {
                    return(DispatchCommit(c));
                }

                return(_sequencer.Handle(c));
            },
                intervalInMilliseconds);

            RegisterHealthChecks(pollerName);
        }
Example #7
0
 public void Start()
 {
     _client = new PollingClient2(_storeEvents.Advanced, Handle, _options.WaitInterval);
     _client.StartFrom();
 }