示例#1
0
        /// <summary>
        /// Starts observing commits and dispatching them..
        /// </summary>
        /// <returns></returns>
        public async Task Start()
        {
            if (_isStarted.EnsureCalledOnce())
            {
                return;
            }

            string checkpointToken = await _checkpointRepository.Get();

            _subscription = _eventStoreClient.Subscribe(checkpointToken, async commit =>
            {
                try
                {
                    await _dispatchCommit(commit, _disposed.Token);
                    await _checkpointRepository.Put(commit.CheckpointToken);
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(
                        ExtensionMethods.FormatWith(Messages.ExceptionHasOccuredWhenDispatchingACommit, new[] { commit.ToString() }),
                        ex);
                    _projectedCommits.OnError(ex);
                    throw;
                }
                _projectedCommits.OnNext(commit);
            });
        }
示例#2
0
        protected async Task Dispatch(
            string streamId,
            Guid eventId,
            int version,
            DateTimeOffset timeStamp,
            string checkpointToken,
            IReadOnlyDictionary <string, object> headers,
            object @event)
        {
            var eventType = @event.GetType();
            var dispatchInternalMethod = typeof(ProjectionDispatcher).GetRuntimeMethods()
                                         .Single(m => m.Name.Equals("DispatchInternal", StringComparison.Ordinal))
                                         .MakeGenericMethod(eventType);

            try
            {
                await(Task) dispatchInternalMethod.Invoke(this, new[] { streamId, eventId, version, timeStamp, headers, @event });
                await _checkpointRepository.Put(checkpointToken);
            }
            catch (Exception ex)
            {
                Logger.ErrorException(
                    Messages.ExceptionHasOccuredWhenDispatchingACommit,
                    ex,
                    eventId);
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Starts observing commits and dispatching them..
        /// </summary>
        /// <returns></returns>
        public async Task Start()
        {
            if (_isStarted.EnsureCalledOnce())
            {
                return;
            }

            string checkpointToken = await _checkpointRepository.Get();

            /* string checkpointToken = null;
             * await _retryPolicy.Retry(async () => checkpointToken = await _checkpointRepository.Get(), _disposed.Token); //TODO should have different retry policy? */
            _subscription = _eventStoreClient.Subscribe(checkpointToken, async commit =>
            {
                try
                {
                    await _retryPolicy.Retry(() => _dispatchCommit(commit, _disposed.Token), _disposed.Token);
                    await _retryPolicy.Retry(() => _checkpointRepository.Put(commit.CheckpointToken), _disposed.Token);
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(
                        Messages.ExceptionHasOccuredWhenDispatchingACommit.FormatWith(commit.ToString()),
                        ex);
                    _projectedCommits.OnError(ex);
                    throw;
                }
                _projectedCommits.OnNext(commit);
            });
        }