///<inheritdoc /> public Task Handle(string topic, byte[] message, CancellationToken token) { if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var messageType = _typeTopicMap.Get(topic); if (messageType == null) { throw new InvalidOperationException( $"Topic '{topic}' has no message type registered with: {_typeTopicMap.GetType()}."); } var deserialized = _serializer.Deserialize(messageType, message); if (deserialized == null) { throw new InvalidOperationException( $"Serializer {_serializer.GetType()} returned null for the {message.Length}-byte message of type {messageType}."); } return(_messageHandlerInvoker.Invoke(deserialized, token)); }
public void Execute(OnHandleMessage pipelineEvent) { var state = pipelineEvent.Pipeline.State; var processingStatus = state.GetProcessingStatus(); if (processingStatus == ProcessingStatus.Ignore || processingStatus == ProcessingStatus.MessageHandled) { return; } var transportMessage = state.GetTransportMessage(); var message = state.GetMessage(); if (transportMessage.HasExpired()) { return; } try { var messageHandlerInvokeResult = _messageHandlerInvoker.Invoke(pipelineEvent); if (messageHandlerInvokeResult.Invoked) { state.SetMessageHandler(messageHandlerInvokeResult.MessageHandler); } else { _events.OnMessageNotHandled(this, new MessageNotHandledEventArgs( pipelineEvent, state.GetWorkQueue(), state.GetErrorQueue(), transportMessage, message)); if (!_configuration.RemoveMessagesNotHandled) { var error = string.Format(Resources.MessageNotHandledFailure, message.GetType().FullName, transportMessage.MessageId, state.GetErrorQueue().Uri.Secured()); _log.Error(error); transportMessage.RegisterFailure(error); using (var stream = _serializer.Serialize(transportMessage)) { state.GetErrorQueue().Enqueue(transportMessage, stream); } } else { _log.Warning(string.Format(Resources.MessageNotHandledIgnored, message.GetType().FullName, transportMessage.MessageId)); } } } catch (Exception ex) { var exception = ex.TrimLeading <TargetInvocationException>(); _events.OnHandlerException( this, new HandlerExceptionEventArgs( pipelineEvent, transportMessage, message, state.GetWorkQueue(), state.GetErrorQueue(), exception)); throw exception; } }