/// <summary> /// Processes a set of received <see cref="EventData" />. /// </summary> /// /// <param name="partitionContext">Contains information about the partition from which events are sourced and provides a means of creating checkpoints for that partition.</param> /// <param name="events">The received events to be processed.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>A task to be resolved on when the operation has completed.</returns> /// public override Task ProcessEventsAsync(PartitionContext partitionContext, IEnumerable <EventData> events, CancellationToken cancellationToken) { OnProcessEvents?.Invoke(partitionContext, events, cancellationToken); return(Task.CompletedTask); }
public async Task Start() { _eventProcessorHost = new EventProcessorHost( _settings.EntityPath, PartitionReceiver.DefaultConsumerGroupName, _settings.ConnectionString, string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", _settings.StorageAccountName, _settings.StorageAccountKey), _settings.StorageContainerName); EventProcessorFactory <T> eventProcessorFactory = new EventProcessorFactory <T>(); await _eventProcessorHost.RegisterEventProcessorFactoryAsync(eventProcessorFactory); eventProcessorFactory.Processor.OnEventClose += (context, reason) => { OnEventClose?.Invoke(context, reason); }; eventProcessorFactory.Processor.OnEventOpen += (context) => { OnEventOpen?.Invoke(context); }; eventProcessorFactory.Processor.OnEventError += (context, error) => { OnEventError?.Invoke(context, error); }; eventProcessorFactory.Processor.OnProcessEvents += (context, eventMessages) => { OnProcessEvents?.Invoke(context, eventMessages); }; }
public Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { List <EventMessage <T> > eventMessages = new List <EventMessage <T> >(); foreach (var message in messages) { eventMessages.Add(new EventMessage <T>(message)); } OnProcessEvents?.Invoke(context, eventMessages); return(context.CheckpointAsync()); }
/// <summary> /// Adds new uninitialized event processors instances to this hub. /// </summary> /// /// <param name="amount">The amount of event processors to add.</param> /// public void AddEventProcessors(int amount) { for (int i = 0; i < amount; i++) { var eventProcessor = new ShortWaitTimeMock ( ConsumerGroup, InnerPartitionManager, Connection, Options ); if (OnInitialize != null) { eventProcessor.InitializeProcessingForPartitionAsync = (partitionContext) => { OnInitialize(partitionContext); return(Task.CompletedTask); }; } if (OnClose != null) { eventProcessor.ProcessingForPartitionStoppedAsync = (partitionContext, reason) => { OnClose(partitionContext, reason); return(Task.CompletedTask); }; } eventProcessor.ProcessEventsAsync = (partitionContext, events) => { OnProcessEvents?.Invoke(partitionContext, events); return(Task.CompletedTask); }; eventProcessor.ProcessExceptionAsync = (partitionContext, exception) => { OnProcessException?.Invoke(partitionContext, exception); return(Task.CompletedTask); }; EventProcessors.Add(eventProcessor); } }
/// <summary> /// Processes a set of received <see cref="EventData" />. /// </summary> /// /// <param name="events">The received events to be processed.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>A task to be resolved on when the operation has completed.</returns> /// public Task ProcessEventsAsync(IEnumerable <EventData> events, CancellationToken cancellationToken) { OnProcessEvents?.Invoke(AssociatedPartitionContext, AssociatedCheckpointManager, events, cancellationToken); return(Task.CompletedTask); }