public void RaiseMessageSerializationException(OpenedQueue queue, Message msg, string errorMessage) { var copy = MessageSerializationException; if (copy == null) { return; } var messageInformation = new FileCurrentMessageInformation { FileMessage = msg, Queue = queue, Message = null, Source = queue.RootUri, MessageId = Guid.Empty }; copy(messageInformation, new SerializationException(errorMessage)); }
private void ProcessMessage( Message message, OpenedQueue messageQueue, TransactionScope tx, Func <CurrentMessageInformation, bool> messageRecieved, Action <CurrentMessageInformation> beforeMessageTransactionCommit, Action <CurrentMessageInformation> beforeMessageTransactionRollback, Action <CurrentMessageInformation, Exception> messageCompleted) { Exception ex = null; currentMessageInformation = CreateMessageInformation(messageQueue, message, null, null); try { // deserialization errors do not count for module events var messages = DeserializeMessages(messageQueue, message, MessageSerializationException); try { foreach (object msg in messages) { currentMessageInformation = CreateMessageInformation(messageQueue, message, messages, msg); if (TransportUtil.ProcessSingleMessage(currentMessageInformation, messageRecieved) == false) { Discard(currentMessageInformation.Message); } } } catch (Exception e) { ex = e; logger.Error("Failed to process message", e); } } catch (Exception e) { ex = e; logger.Error("Failed to deserialize message", e); } finally { Action sendMessageBackToQueue = null; if (message != null && (messageQueue.IsTransactional == false || consumeInTransaction == false)) { sendMessageBackToQueue = () => messageQueue.Send(message); } var messageHandlingCompletion = new MessageHandlingCompletion(tx, sendMessageBackToQueue, ex, messageCompleted, beforeMessageTransactionCommit, beforeMessageTransactionRollback, logger, MessageProcessingFailure, currentMessageInformation); messageHandlingCompletion.HandleMessageCompletion(); currentMessageInformation = null; } }