private void ProcessMessage(
            Message message,
            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
                object[] 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 SqlQueueCurrentMessageInformation
                        {
                            AllMessages        = messages,
                            Message            = msg,
                            Destination        = queueEndpoint,
                            MessageId          = messageId,
                            Source             = source,
                            TransportMessageId = message.Id.ToString(),
                            Queue            = queue,
                            TransportMessage = message
                        };

                        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
            {
                var messageHandlingCompletion = new SqlMessageHandlingCompletion(_sqlQueueManager, null, ex, messageCompleted, beforeTransactionCommit, beforeTransactionRollback, logger,
                                                                                 MessageProcessingFailure, currentMessageInformation);
                messageHandlingCompletion.HandleMessageCompletion();
                currentMessageInformation = null;
            }
        }
        private void ProcessMessage(
            Message message,
            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
                object[] 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 SqlQueueCurrentMessageInformation
                        {
                            AllMessages = messages,
                            Message = msg,
                            Destination = queueEndpoint,
                            MessageId = messageId,
                            Source = source,
                            TransportMessageId = message.Id.ToString(),
                            Queue = queue,
                            TransportMessage = message
                        };

                        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
            {
                var messageHandlingCompletion = new SqlMessageHandlingCompletion(_sqlQueueManager, null, ex, messageCompleted, beforeTransactionCommit, beforeTransactionRollback, logger,
                                                                              MessageProcessingFailure, currentMessageInformation);
                messageHandlingCompletion.HandleMessageCompletion();
                currentMessageInformation = null;
            }
        }