/// <summary> /// Handles the <see cref="IMessageReceiver.FeedMessageReceived"/> event /// </summary> /// <param name="sender">A <see cref="object"/> representation of the instance raising the event</param> /// <param name="e">A <see cref="FeedMessageReceivedEventArgs"/> instance containing event information</param> private void OnMessageReceived(object sender, FeedMessageReceivedEventArgs e) { var message = e.Message; var validationResult = _messageValidator.Validate(message); switch (validationResult) { case ValidationResult.FAILURE: Log.Warn($"{WriteMessageInterest()}Validation of message=[{message}] failed. Raising OnUnparsableMessageReceived event"); var messageType = _messageDataExtractor.GetMessageTypeFromMessage(message); var eventArgs = new UnparsableMessageEventArgs(messageType, message.ProducerId.ToString(), message.EventId, e.RawMessage); Dispatch(OnUnparsableMessageReceived, eventArgs, "OnUnparsableMessageReceived"); return; case ValidationResult.PROBLEMS_DETECTED: Log.Warn($"{WriteMessageInterest()}Problems were detected while validating message=[{message}], but the message is still eligible for further processing."); _messageProcessor.ProcessMessage(message, MessageInterest, e.RawMessage); return; case ValidationResult.SUCCESS: Metric.Context("FEED").Meter($"FeedSession->MessageReceived ({MessageInterest.ProducerId})", Unit.Items).Mark(); Log.Debug($"{WriteMessageInterest()}Message=[{message}] successfully validated. Continuing with message processing."); _messageProcessor.ProcessMessage(message, MessageInterest, e.RawMessage); return; default: Log.Error($"{WriteMessageInterest()}ValidationResult {Enum.GetName(typeof(ValidationResult), validationResult)} is not supported. Aborting processing of message=[{message}]."); return; } }
/// <summary> /// Processes the received <see cref="FeedMessage"/> /// </summary> /// <param name="feedMessage">The <see cref="FeedMessage"/> to process.</param> /// <param name="rawMessage">A raw message received from the feed</param> private void ProcessMessage(FeedMessage feedMessage, byte[] rawMessage) { if (feedMessage is alive alive) { var args = new FeedMessageReceivedEventArgs(alive, null, rawMessage); Dispatch(AliveReceived, args, "AliveReceived"); } }
/// <summary> /// Handles the <see cref="IFeedMessageProcessor.MessageProcessed"/> event /// </summary> /// <param name="sender">A <see cref="object"/> representation of the instance raising the event</param> /// <param name="e">A <see cref="FeedMessageReceivedEventArgs"/> instance containing event information</param> private void OnMessageProcessed(object sender, FeedMessageReceivedEventArgs e) { var processingTook = string.Empty; var sdkProcessingTime = DateTime.Now - SdkInfo.FromEpochTime(e.Message.ReceivedAt); if (sdkProcessingTime.TotalMilliseconds > 500) { processingTook = $" Sdk processing took {(int)sdkProcessingTime.TotalMilliseconds}ms"; } ExecutionLog.LogDebug($"Dispatching {e.Message.GetType().Name} for {e.Message.EventId} ({e.Message.GeneratedAt}).{processingTook}"); var dispatcher = SelectDispatcher(e.Message); dispatcher.Dispatch(e.Message, e.RawMessage); }
/// <summary> /// Handles the <see cref="IMessageReceiver.FeedMessageReceived"/> event /// </summary> /// <param name="sender">A <see cref="object"/> representation of the instance raising the event</param> /// <param name="e">A <see cref="FeedMessageReceivedEventArgs"/> instance containing event information</param> private void OnFeedMessageReceived(object sender, FeedMessageReceivedEventArgs e) { var message = e.Message; var validationResult = _messageValidator.Validate(message); switch (validationResult) { case ValidationResult.FAILURE: _log.LogWarning($"Validation of message=[{message}] failed. Raising OnUnparsableMessageReceived event"); MessageType messageType; try { messageType = _messageDataExtractor.GetMessageTypeFromMessage(message); } catch (ArgumentException ex) { _log.LogError($"An error occurred while determining the MessageType of the message whose validation has failed. Message={message}", ex); return; } var eventArgs = new UnparsableMessageEventArgs(messageType, message.ProducerId.ToString(), message.EventId, e.RawMessage); Dispatch(UnparsableMessageReceived, eventArgs, "OnUnparsableMessageReceived"); return; case ValidationResult.PROBLEMS_DETECTED: _log.LogWarning($"Problems were detected while validating message=[{message}], but the message is still eligible for further processing."); return; case ValidationResult.SUCCESS: _log.LogDebug($"Message=[{message}] successfully validated. Continuing with message processing"); ProcessMessage(message, e.RawMessage); return; default: _log.LogError($"ValidationResult {Enum.GetName(typeof(ValidationResult), validationResult)} is not supported. Aborting processing of message=[{message}]"); return; } }
private void OnProcessorMessageProcessedEvent(object sender, FeedMessageReceivedEventArgs e) { //Debug.WriteLine($"{ProcessorId} - CompositeMessageProcessor.OnProcessorMessageProcessedEvent called."); var sendingProcessor = (IFeedMessageProcessor)sender; int index; for (index = 0; index < _processors.Count; index++) { if (sendingProcessor == _processors[index]) { break; } } if (index < _processors.Count - 1) { _processors[index + 1].ProcessMessage(e.Message, e.Interest, e.RawMessage); return; } //Debug.WriteLine($"{ProcessorId} - CompositeMessageProcessor.OnProcessorMessageProcessedEvent finishing."); RaiseOnMessageProcessedEvent(e); }
/// <summary> /// Raise a <see cref="MessageProcessed"/> event /// </summary> /// <param name="e">Send the <see cref="FeedMessage"/> originally received</param> protected void RaiseOnMessageProcessedEvent(FeedMessageReceivedEventArgs e) { Guard.Argument(e, nameof(e)).NotNull(); MessageProcessed?.Invoke(this, e); }
/// <summary> /// Handles the <see cref="IFeedMessageProcessor.MessageProcessed"/> event /// </summary> /// <param name="sender">A <see cref="object"/> representation of the instance raising the event</param> /// <param name="e">A <see cref="FeedMessageReceivedEventArgs"/> instance containing event information</param> private void OnMessageProcessed(object sender, FeedMessageReceivedEventArgs e) { var dispatcher = SelectDispatcher(e.Message); dispatcher.Dispatch(e.Message, e.RawMessage); }
private void OnUserSessionMessageReceived(object sender, FeedMessageReceivedEventArgs feedMessageReceivedEventArgs) { var manager = _producerRecoveryManagers.FirstOrDefault(f => f.Key.Id == feedMessageReceivedEventArgs.Message.ProducerId).Value; manager?.ProcessUserMessage(feedMessageReceivedEventArgs.Message, feedMessageReceivedEventArgs.Interest); }
private void OnProcessorMessageProcessedEvent(object sender, FeedMessageReceivedEventArgs e) { ExecutionLog.Debug($"{ProcessorId} - CompositeMessageProcessor.OnProcessorMessageProcessedEvent called by {sender?.GetType().Name}"); RaiseOnMessageProcessedEvent(e); }
/// <summary> /// Raise a <see cref="MessageProcessed"/> event /// </summary> /// <param name="e">Send the <see cref="FeedMessage"/> originally received</param> protected void RaiseOnMessageProcessedEvent(FeedMessageReceivedEventArgs e) { Contract.Requires(e != null); MessageProcessed?.Invoke(this, e); }