public AuditIngestionComponent( Settings settings, IDocumentStore documentStore, RawEndpointFactory rawEndpointFactory, LoggingSettings loggingSettings, BodyStorageFeature.BodyStorageEnricher bodyStorageEnricher, IEnrichImportedAuditMessages[] enrichers, AuditIngestionCustomCheck.State ingestionState ) { var errorHandlingPolicy = new AuditIngestionFaultPolicy(documentStore, loggingSettings, FailedMessageFactory, OnCriticalError); auditPersister = new AuditPersister(documentStore, bodyStorageEnricher, enrichers); var ingestor = new AuditIngestor(auditPersister, settings); var ingestion = new AuditIngestion( (messageContext, dispatcher) => ingestor.Ingest(messageContext), dispatcher => ingestor.Initialize(dispatcher), settings.AuditQueue, rawEndpointFactory, errorHandlingPolicy, OnCriticalError); failedImporter = new ImportFailedAudits(documentStore, ingestor, rawEndpointFactory); watchdog = new Watchdog(ingestion.EnsureStarted, ingestion.EnsureStopped, ingestionState.ReportError, ingestionState.Clear, settings.TimeToRestartAuditIngestionAfterFailure, log, "failed message ingestion"); }
async Task Loop() { var contexts = new List <MessageContext>(settings.MaximumConcurrencyLevel); while (await channel.Reader.WaitToReadAsync().ConfigureAwait(false)) { // will only enter here if there is something to read. try { // as long as there is something to read this will fetch up to MaximumConcurrency items while (channel.Reader.TryRead(out var context)) { contexts.Add(context); } await ingestor.Ingest(contexts).ConfigureAwait(false); } finally { contexts.Clear(); } } // will fall out here when writer is completed }