private void ProcessMessage(Message message, TransactionScope tx, Func<CurrentMessageInformation, bool> messageRecieved, Action<CurrentMessageInformation, Exception> messageCompleted, Action<CurrentMessageInformation> beforeTransactionCommit, Action<CurrentMessageInformation> beforeTransactionRollback) { Exception ex = null; try { //deserialization errors do not count for module events #pragma warning disable 420 Interlocked.Increment(ref _currentlyProccessingCount); var messages = DeserializeMessages(message); try { var messageId = new Guid(message.Headers["id"]); var source = new Uri(message.Headers["source"]); foreach (var msg in messages) { _currentMessageInformation = new RhinoFileCurrentMessageInformation { AllMessages = messages, Message = msg, Destination = _endpoint, MessageId = messageId, Source = source, TransportMessageId = message.Id.ToString(), Queue = _queue, TransportMessage = message }; if (!TransportUtil.ProcessSingleMessage(_currentMessageInformation, messageRecieved)) 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 { var messageHandlingCompletion = new MessageHandlingCompletion(tx, null, ex, messageCompleted, beforeTransactionCommit, beforeTransactionRollback, _logger, MessageProcessingFailure, _currentMessageInformation); messageHandlingCompletion.HandleMessageCompletion(); _currentMessageInformation = null; Interlocked.Decrement(ref _currentlyProccessingCount); #pragma warning restore 420 } }
private object[] DeserializeMessages(Message message) { try { return _messageSerializer.Deserialize(new MemoryStream(message.Data)); } catch (Exception e) { try { _logger.Error("Error when serializing message", e); var serializationError = MessageSerializationException; if (serializationError != null) { _currentMessageInformation = new RhinoFileCurrentMessageInformation { Message = message, Source = new Uri(message.Headers["source"]), MessageId = new Guid(message.Headers["id"]), TransportMessageId = message.Id.ToString(), TransportMessage = message, Queue = _queue, }; serializationError(_currentMessageInformation, e); } } catch (Exception e2) { _logger.Error("Error when notifying about serialization exception", e2); } throw; } }