示例#1
0
        public async Task SubscribeAsync()
        {
            var lastCheckpoint = await _checkpointRepository.GetLastCheckpointAsync(GetProjectionName());

            var settings = new CatchUpSubscriptionSettings(
                maxLiveQueueSize: 10000,
                readBatchSize: 500,
                verboseLogging: false,
                resolveLinkTos: false,
                subscriptionName: "Meetup");

            _eventStoreConnection.SubscribeToAllFrom(
                lastCheckpoint: lastCheckpoint,
                settings: settings,
                eventAppeared: async(sub, @event) =>
            {
                if (@event.OriginalEvent.EventType.StartsWith("$"))
                {
                    return;
                }

                try
                {
                    await _mediator.Publish(new ProjectionNotification
                    {
                        DomainEvent = GetDomainEventByType(@event.OriginalEvent.EventType, @event.OriginalEvent.Data)
                    });

                    await _checkpointRepository.SetLastCheckpointAsync(@event.OriginalPosition.Value, GetProjectionName());
                }
                catch (Exception exception)
                {
                    _logger.LogError(exception, exception.Message);
                }
            },
                liveProcessingStarted: (sub) =>
            {
                _logger.LogInformation("{SubscriptionName} subscription started.", sub.SubscriptionName);
            },
                subscriptionDropped: (sub, subDropReason, exception) =>
            {
                _logger.LogWarning("{SubscriptionName} dropped. Reason: {SubDropReason}.", sub.SubscriptionName, subDropReason);
            });
        }