Example #1
0
        /// <summary>
        /// Gets the <see cref="ScopedEventProcessor" /> registered for the specified key or null if none is registered
        /// </summary>
        /// <param name="key">Key to search for</param>
        /// <returns>The registered <see cref="IEnumerable{ScopedEventProcessor}" /> for the key or null if none is registered</returns>
        public IEnumerable <ScopedEventProcessor> GetProcessorsFor(ScopedEventProcessorKey key)
        {
            ConcurrentDictionary <EventProcessorId, ScopedEventProcessor> processors;
            var dictionary = _scopedProcessors.TryGetValue(key, out processors) ? processors : null;

            return(dictionary?.Values.ToArray() ?? Enumerable.Empty <ScopedEventProcessor>());
        }
Example #2
0
 /// <summary>
 /// Instantiates an instance of <see cref="ScopedEventProcessor" />
 /// </summary>
 /// <param name="tenant">The <see cref="TenantId" /> that this processor is scoped to.</param>
 /// <param name="processor">An <see cref="IEventProcessor" /> to process the event</param>
 /// <param name="getOffsetRepository">A factory function to return a correctly scoped instance of <see cref="IEventProcessorOffsetRepository" /></param>
 /// <param name="getUnprocessedEventsFetcher">A factory function to return a correctly scoped instance of <see cref="IFetchUnprocessedEvents" /></param>
 /// <param name="logger">An <see cref="ILogger" /> to log messages</param>
 public ScopedEventProcessor(TenantId tenant, IEventProcessor processor, FactoryFor <IEventProcessorOffsetRepository> getOffsetRepository,
                             FactoryFor <IFetchUnprocessedEvents> getUnprocessedEventsFetcher, ILogger logger)
 {
     LastVersionProcessed = CommittedEventVersion.None;
     _tenant    = tenant;
     _processor = processor;
     _logger    = logger;
     Key        = new ScopedEventProcessorKey(tenant, processor.Event);
     _getUnprocessedEventsFetcher = getUnprocessedEventsFetcher;
     _getOffsetRepository         = getOffsetRepository;
 }
Example #3
0
        void Process(CommittedEventEnvelope envelope, ExecutionContext executionContext)
        {
            ConcurrentDictionary <EventProcessorId, ScopedEventProcessor> processors = null;
            var key = new ScopedEventProcessorKey(executionContext.Tenant, envelope.Metadata.Artifact);

            if (_scopedProcessors.TryGetValue(key, out processors))
            {
                if (processors?.Values.Any() ?? false)
                {
                    processors.Values.ForEach(_ => _.Process(envelope));
                }
            }
            if (processors == null || processors.Count == 0)
            {
                _logger.Warning($"No Processor registered for {key}");
            }
        }