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);
        }
Exemple #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);
            }
        }
        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}");
        }
 /// <summary>
 /// Start automatic polling.
 /// </summary>
 /// <param name="checkpointTokenFrom"></param>
 /// <param name="intervalInMilliseconds"></param>
 /// <param name="checkpointTokenSequenced">When there is a rebuild we already know that commit until the
 /// rebuild checkpoint are already sequenced so there is no need to wait for them. All CheckpointToken
 /// less than this value are considered to be sequenced.</param>
 /// <param name="bufferSize"></param>
 /// <param name="pollerName"></param>
 public void StartAutomaticPolling(
     Int64 checkpointTokenFrom,
     Int32 intervalInMilliseconds,
     Int64 checkpointTokenSequenced,
     Int32 bufferSize,
     String pollerName)
 {
     Init(checkpointTokenFrom, intervalInMilliseconds, checkpointTokenSequenced, bufferSize, pollerName);
     _innerClient.StartFrom(checkpointTokenFrom);
     Status = CommitPollingClientStatus.Polling;
 }
Exemple #6
0
 internal void Start()
 {
     _pollingClient2.StartFrom(_checkpointToObserveFrom);
 }
 public void Start()
 {
     _client = new PollingClient2(_storeEvents.Advanced, Handle, _options.WaitInterval);
     _client.StartFrom();
 }