/// <inheritdoc /> public BoolResult StartProcessing(OperationContext context, EventSequencePoint sequencePoint, IPartitionReceiveHandler processor) { Tracer.Info(context, $"{Tracer.Name}: Initializing event processing for event hub '{_configuration.EventHubName}' and consumer group '{_configuration.ConsumerGroupName}'."); if (_partitionReceiver == null) { _partitionReceiver = _eventHubClient.CreateReceiver( _configuration.ConsumerGroupName, PartitionId, GetInitialOffset(context, sequencePoint), new ReceiverOptions() { Identifier = _hostName }); _partitionReceiver.SetReceiveHandler(processor); } return(BoolResult.Success); }
private async Task ProcessEventsCoreAsync(ProcessEventsInput input, ContentLocationEventDataSerializer eventDataSerializer) { var context = input.Context; var counters = input.EventStoreCounters; await context.PerformOperationAsync( Tracer, async() => { int filteredEvents = 0; foreach (var message in input.Messages) { // Extracting information from the message var foundEventFilter = message.Properties.TryGetValue(EventFilterKey, out var eventFilter); message.Properties.TryGetValue(OperationIdKey, out var operationId); var sender = TryGetMessageSender(message) ?? "Unknown sender"; var eventTimeUtc = message.SystemProperties.EnqueuedTimeUtc; var eventProcessingDelay = DateTime.UtcNow - eventTimeUtc; // Creating nested context with operationId as a guid. This helps to correlate operations on a worker and a master machines. context = CreateNestedContext(context, operationId?.ToString()); Tracer.Debug(context, $"{Tracer.Name}.ReceivedEvent: ProcessingDelay={eventProcessingDelay}, Sender={sender}, OpId={operationId}, SeqNo={message.SystemProperties.SequenceNumber}, EQT={eventTimeUtc}, Filter={eventFilter}, Size={message.Body.Count}."); Tracer.TrackMetric(context, EventProcessingDelayInSecondsMetricName, (long)eventProcessingDelay.TotalSeconds); counters[ReceivedMessagesTotalSize].Add(message.Body.Count); counters[ReceivedEventBatchCount].Increment(); if (!foundEventFilter || !string.Equals(eventFilter as string, _configuration.Epoch)) { counters[FilteredEvents].Increment(); filteredEvents++; continue; } // Deserializing a message IReadOnlyList <ContentLocationEventData> eventDatas; using (counters[Deserialization].Start()) { eventDatas = eventDataSerializer.DeserializeEvents(message); } counters[ReceivedEventsCount].Add(eventDatas.Count); // Dispatching deserialized events data using (counters[DispatchEvents].Start()) { foreach (var eventData in eventDatas) { // An event processor may fail to process the event, but we will save the sequence point anyway. await DispatchAsync(context, eventData, counters); } } _lastProcessedSequencePoint = new EventSequencePoint(message.SystemProperties.SequenceNumber); } Counters.Append(counters); return(BoolResult.Success); },
private EventPosition GetInitialOffset(OperationContext context, EventSequencePoint sequencePoint) { context.TraceDebug($"{Tracer.Name}.GetInitialOffset: consuming events from '{sequencePoint}'."); return(sequencePoint.EventPosition); }
private EventPosition GetInitialOffset(OperationContext context, EventSequencePoint sequencePoint) { Tracer.Debug(context, $"Consuming events from '{sequencePoint}'."); return(sequencePoint.EventPosition); }