Exemple #1
0
        public IStreamSubscription Create(
            ConsumerGroup consumerGroup,
            SubscriptionStartOptions startOptions,
            ProcessEventsHandler eventsHandler)
        {
            var builder = containerProvider
                          .GetStreamContainer()
                          .GetChangeFeedProcessorBuilder <EventDocument>(
                GetProcessorName(consumerGroup),
                (c, ct) => eventsHandler(c.Where(ExcludeMetaDataChanges).ToArray(), ct))
                          .WithLeaseContainer(containerProvider.GetSubscriptionContainer())
                          .WithMaxItems(100)
                          .WithPollInterval(TimeSpan.FromMilliseconds(1000));

            if (startOptions == SubscriptionStartOptions.FromBegining)
            {
                // Instruct processor to start from beginning.
                // see https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-processor#reading-from-the-beginning
                builder.WithStartTime(DateTime.MinValue.ToUniversalTime());
            }

            if (!string.IsNullOrEmpty(consumerGroup.Instance))
            {
                builder.WithInstanceName(consumerGroup.Instance);
            }

            return(new CosmosSubscriptionProcessor(
                       telemetry,
                       builder.Build(),
                       consumerGroup));
        }
 public IStreamSubscription SubscribeToStreams(
     ConsumerGroup consumerGroup,
     SubscriptionStartOptions startOptions,
     ProcessEventsHandler eventsHandler)
 => subscriptionFactory
 .Create(
     Arguments.EnsureNotNull(consumerGroup, nameof(consumerGroup)),
     startOptions,
     Arguments.EnsureNotNull(eventsHandler, nameof(eventsHandler)));
 IStreamSubscription IStreamSubscriptionFactory.Create(
     ConsumerGroup consumerGroup,
     SubscriptionStartOptions startOptions,
     ProcessEventsHandler eventsHandler)
 => throw new NotImplementedException();