Пример #1
0
    public async Task StartAsync()
    {
        Container itemContainer = await _containerService.GetContainerAsync <TSourcedEvent>();

        Container leaseContainer = await _leaseContainerProvider.GetLeaseContainerAsync();

        ChangeFeedProcessorBuilder builder = itemContainer
                                             .GetChangeFeedProcessorBuilder <TSourcedEvent>(_options.ProcessorName, (changes, token) =>
                                                                                            OnChangesAsync(changes, token, itemContainer.Id))
                                             .WithLeaseContainer(leaseContainer)
                                             .WithInstanceName(_options.InstanceName)
                                             .WithErrorNotification((_, exception) => OnErrorAsync(exception, itemContainer.Id));

        if (_options.PollInterval.HasValue)
        {
            builder.WithPollInterval(_options.PollInterval.Value);
        }

        _processor = builder.Build();

        _logger.LogInformation("Starting change feed processor for container {ContainerName} with key {ProjectionKey} and processor name {ProcessorName}",
                               itemContainer.Id,
                               typeof(TProjectionKey).Name,
                               _options.ProcessorName);

        await _processor.StartAsync();

        _logger.LogInformation("Successfully started change feed processor for container {ContainerName} with key {ProjectionKey} and processor name {ProcessorName}",
                               itemContainer.Id,
                               typeof(TProjectionKey).Name,
                               _options.ProcessorName);
    }