예제 #1
0
        /// <summary>
        /// Creates IOutboundFaFMq implementation with the configuration provided by provider.
        /// </summary>
        /// <param name="configurationProvider">The configuration provider</param>
        /// <param name="logger">The queue logger</param>
        /// <param name="configurationIdentifier">The configuration identifier</param>
        public static IOutboundFaFMq <TMessage> CreateOutboundFaF <TMessage>(IQueueConfigurationProvider configurationProvider, string configurationIdentifier, IQueueLogger logger = null)
        {
            #region Initialization
            logger = logger ?? new NoLog();
            Dictionary <string, string> configuration = null;
            #endregion

            try
            {
                #region Configuration Retrieval
                configuration = RetrieveAndValidateConfiguration(configurationProvider, configurationIdentifier);
                #endregion

                #region Creating Implementation
                // Getting type details.
                var messageQueueTypeInfo = Type.GetType(configuration[CommonConfigurationKeys.Implementation], true, true);

                // Substituting generic parameters.
                var typeParams      = new[] { typeof(TMessage) };
                var genericTypeInfo = messageQueueTypeInfo.MakeGenericType(typeParams);

                // Creating instance.
                var messagingQueue =
                    Activator.CreateInstance(genericTypeInfo, configuration, logger) as IOutboundFaFMq <TMessage>;
                #endregion

                #region Return
                return(messagingQueue);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                var queueException = new QueueException(QueueErrorCode.FailedToInstantiateOutboundFaFMq,
                                                        ErrorMessages.FailedToInstantiateOutboundFaF, ex);

                queueException.Data["Implementation"] = configuration?[CommonConfigurationKeys.Implementation];

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw queueException;
            }
        }
        public override void Response(TResponse response)
        {
            try
            {
                #region Sending Response
                // Preparing response.
                var messageToClient = new NetMQMessage();
                messageToClient.Append(clientAddress);
                messageToClient.AppendEmptyFrame();
                messageToClient.Append(MessageQueueCommonItems.SerializeToJson(response));

                // Sending response.
                responseChannel.SendMultipartMessage(messageToClient);
                #endregion
            }
            catch (QueueException queueException)
            {
                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          errorCode: QueueErrorCode.FailedToSendResponseMessage,
                          message: ErrorMessages.FailedToSendResponseMessage,
                          innerException: ex,
                          queueContext: CommonItems.ZeroMqName,
                          logger: logger);
            }
        }
        public override void Response(TResponse response)
        {
            try
            {
                #region Sending Response
                // Preparing response.
                var responseBytes = MessageQueueCommonItems.SerializeToJsonBytes(response);

                // Sending response.
                model.BasicPublish(exchange, routingKey, replyProperties, responseBytes);

                // Acknowledging message.
                if (acknowledgment)
                {
                    model.BasicAck(deliveryTag, false);
                }
                #endregion
            }
            catch (QueueException queueException)
            {
                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          errorCode: QueueErrorCode.FailedToSendResponseMessage,
                          message: ErrorMessages.FailedToSendResponseMessage,
                          innerException: ex,
                          queueContext: CommonItems.RabbitMqName,
                          context: new Dictionary <string, string>
                {
                    [CommonContextKeys.ExchangeName] = exchange,
                    [CommonContextKeys.RoutingKey]   = routingKey,
                    [ContextKeys.ReplyTo]            = replyProperties.ReplyTo
                },
                          logger: logger);
            }
        }
예제 #4
0
        /// <summary>
        /// Helper method to validate and collect ZeroMq parameters.
        /// </summary>
        public static ZeroMqConfiguration CollectZmqConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Initialization
                var zeroMqConfiguration = new ZeroMqConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();
                #endregion

                #region Collecting Common Configuration
                MessageQueueCommonItems.CollectCommonConfiguration(ref rawConfiguration, zeroMqConfiguration, ZeroMqConfigurationKeys.GetAllKeys());
                #endregion

                #region Collecting Other Configuration
                // Nothing to collect.
                #endregion

                #region Return
                return(zeroMqConfiguration);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, ZeroMqName);
                #endregion

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, ZeroMqName, logger: logger);
            }
        }
        /// <summary>
        /// Helper method to prepare and log queue exception.
        /// NOTE: If logger is null, exception will not be logged.
        /// </summary>
        public static QueueException PrepareAndLogQueueException(QueueErrorCode errorCode, string message, Exception innerException, string queueContext, string queueName = "", string address = "", Dictionary <string, string> context = null, IQueueLogger logger = null)
        {
            #region Preparing Queue Exception
            var queueException = new QueueException(errorCode, message, context: new Dictionary <string, string>
            {
                [CommonContextKeys.QueueContext] = queueContext
            }, innerException: innerException);

            if (!string.IsNullOrWhiteSpace(address))
            {
                queueException.Data[CommonContextKeys.Address] = address;
            }

            if (!string.IsNullOrWhiteSpace(queueName))
            {
                queueException.Data[CommonContextKeys.QueueName] = queueName;
            }

            if (context != null)
            {
                foreach (var currentItem in context)
                {
                    queueException.Data[currentItem.Key] = currentItem.Value;
                }
            }
            #endregion

            #region Logging - Error
            logger?.Error(queueException, queueException.Message);
            #endregion

            #region Return
            return(queueException);

            #endregion
        }
예제 #6
0
        /// <summary>
        /// Helper method to validate and collect ZeroMq parameters.
        /// </summary>
        public static ZeroMqConfiguration CollectZmqConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Parameters Validation
                var zeroMqSettings = new ZeroMqConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();

                var notSupportedParams =
                    rawConfiguration.Keys.Where(x => !CommonConfigurationKeys.GetAllKeys().Contains(x) &&
                                                !ZeroMqConfigurationKeys.GetAllKeys().Contains(x)).ToList();

                if (notSupportedParams.Any())
                {
                    throw new QueueException(QueueErrorCode.NotSupportedConfigurationParameters,
                                             ErrorMessages.NotSupportedConfigurationParameters, context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.NotSupportedParameters] = string.Join(",", notSupportedParams)
                    });
                }

                // Address
                if (!rawConfiguration.ContainsKey(CommonConfigurationKeys.Address) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[CommonConfigurationKeys.Address]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           CommonConfigurationKeys.Address),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = CommonConfigurationKeys.Address
                    });
                }

                zeroMqSettings.Address = rawConfiguration[CommonConfigurationKeys.Address];
                #endregion

                #region Return
                return(zeroMqSettings);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, ZeroMqName);
                #endregion

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, ZeroMqName, logger: logger);
            }
        }
예제 #7
0
        /// <summary>
        /// Helper method to validate and collect ServiceBus parameters.
        /// </summary>
        internal static ServiceBusConfiguration CollectSbConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Parameters Validation
                var sbSettings = new ServiceBusConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();

                var notSupportedParams =
                    rawConfiguration.Keys.Where(x => !CommonConfigurationKeys.GetAllKeys().Contains(x) &&
                                                !ServiceBusConfigurationKeys.GetAllKeys().Contains(x)).ToList();

                if (notSupportedParams.Any())
                {
                    throw new QueueException(QueueErrorCode.NotSupportedConfigurationParameters,
                                             ErrorMessages.NotSupportedConfigurationParameters, context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.NotSupportedParameters] = string.Join(",", notSupportedParams)
                    });
                }

                // Address
                if (!rawConfiguration.ContainsKey(CommonConfigurationKeys.Address) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[CommonConfigurationKeys.Address]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter, CommonConfigurationKeys.Address),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = CommonConfigurationKeys.Address
                    });
                }

                sbSettings.Address = rawConfiguration[CommonConfigurationKeys.Address];

                // Namespace Address
                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.NamespaceAddress))
                {
                    if (string.IsNullOrWhiteSpace(rawConfiguration[ServiceBusConfigurationKeys.NamespaceAddress]))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.NamespaceAddress),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.NamespaceAddress
                        });
                    }

                    sbSettings.NamespaceAddress = rawConfiguration[ServiceBusConfigurationKeys.NamespaceAddress];
                }

                // Queue Name
                if (!rawConfiguration.ContainsKey(CommonConfigurationKeys.QueueName) || string.IsNullOrWhiteSpace(rawConfiguration[CommonConfigurationKeys.QueueName]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           CommonConfigurationKeys.QueueName),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = CommonConfigurationKeys.QueueName
                    });
                }

                sbSettings.QueueName = rawConfiguration[CommonConfigurationKeys.QueueName];

                // MaxDeliveryCount
                short maxDeliveryCount;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.MaxDeliveryCount))
                {
                    if (!short.TryParse(rawConfiguration[ServiceBusConfigurationKeys.MaxDeliveryCount], out maxDeliveryCount))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.MaxDeliveryCount),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.MaxDeliveryCount
                        });
                    }
                }
                else
                {
                    maxDeliveryCount = Defaults.MaxDeliveryCount;
                }

                sbSettings.MaxDeliveryCount = maxDeliveryCount;

                // MaxSizeInMegabytes
                long maxSizeInMegabytes;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.MaxSizeInMegabytes))
                {
                    if (!long.TryParse(rawConfiguration[ServiceBusConfigurationKeys.MaxSizeInMegabytes], out maxSizeInMegabytes))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.MaxSizeInMegabytes),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.MaxSizeInMegabytes
                        });
                    }
                }
                else
                {
                    maxSizeInMegabytes = Defaults.MaxSizeInMegabytes;
                }

                sbSettings.MaxSizeInMegabytes = maxSizeInMegabytes;

                // EnableDeadLettering
                bool enableDeadLettering;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.EnableDeadLettering))
                {
                    if (!bool.TryParse(rawConfiguration[ServiceBusConfigurationKeys.EnableDeadLettering], out enableDeadLettering))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.EnableDeadLettering),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.EnableDeadLettering
                        });
                    }
                }
                else
                {
                    enableDeadLettering = Defaults.EnableDeadLettering;
                }

                sbSettings.EnableDeadLettering = enableDeadLettering;

                // EnablePartitioning
                bool enablePartitioning;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.EnablePartitioning))
                {
                    if (!bool.TryParse(rawConfiguration[ServiceBusConfigurationKeys.EnablePartitioning], out enablePartitioning))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.EnablePartitioning),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.EnablePartitioning
                        });
                    }
                }
                else
                {
                    enablePartitioning = Defaults.EnablePartitioning;
                }

                sbSettings.EnablePartitioning = enablePartitioning;

                // RequiresDuplicateDetection
                bool requiresDuplicateDetection;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.RequiresDuplicateDetection))
                {
                    if (!bool.TryParse(rawConfiguration[ServiceBusConfigurationKeys.RequiresDuplicateDetection], out requiresDuplicateDetection))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.RequiresDuplicateDetection),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.RequiresDuplicateDetection
                        });
                    }
                }
                else
                {
                    requiresDuplicateDetection = Defaults.RequiresDuplicateDetection;
                }

                sbSettings.RequiresDuplicateDetection = requiresDuplicateDetection;

                // EnableBatchedOperations
                bool enableBatchedOperations;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.EnableBatchedOperations))
                {
                    if (!bool.TryParse(rawConfiguration[ServiceBusConfigurationKeys.EnableBatchedOperations], out enableBatchedOperations))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.EnableBatchedOperations),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.EnableBatchedOperations
                        });
                    }
                }
                else
                {
                    enableBatchedOperations = Defaults.EnableBatchedOperations;
                }

                sbSettings.EnableBatchedOperations = enableBatchedOperations;

                // MessageTimeToLiveInMinutes
                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.MessageTimeToLiveInMinutes))
                {
                    int messageTimeToLiveInMinutes;

                    if (!int.TryParse(rawConfiguration[ServiceBusConfigurationKeys.MessageTimeToLiveInMinutes], out messageTimeToLiveInMinutes))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.MessageTimeToLiveInMinutes),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.MessageTimeToLiveInMinutes
                        });
                    }

                    sbSettings.MessageTimeToLiveInMinutes = TimeSpan.FromMinutes(messageTimeToLiveInMinutes);
                }
                else
                {
                    sbSettings.MessageTimeToLiveInMinutes = Defaults.MessageTimeToLive;
                }

                // LockDurationInSeconds
                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.LockDurationInSeconds))
                {
                    int lockDurationInSeconds;

                    if (!int.TryParse(rawConfiguration[ServiceBusConfigurationKeys.LockDurationInSeconds], out lockDurationInSeconds))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.LockDurationInSeconds),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.LockDurationInSeconds
                        });
                    }

                    sbSettings.LockDurationInSeconds = TimeSpan.FromSeconds(lockDurationInSeconds);
                }
                else
                {
                    sbSettings.LockDurationInSeconds = Defaults.LockDurationInSeconds;
                }

                // Acknowledgment
                bool acknowledgment;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.Acknowledgment))
                {
                    if (isInbound == false)
                    {
                        throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                                 string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                               ServiceBusConfigurationKeys.Acknowledgment),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.Acknowledgment
                        });
                    }

                    if (!bool.TryParse(rawConfiguration[ServiceBusConfigurationKeys.Acknowledgment], out acknowledgment))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.Acknowledgment),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.Acknowledgment
                        });
                    }
                }
                else
                {
                    acknowledgment = Defaults.Acknowledgment;
                }

                sbSettings.Acknowledgment = acknowledgment;

                // MaxConcurrentReceiveCallback
                ushort maxConcurrentReceiveCallback;

                if (rawConfiguration.ContainsKey(ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback))
                {
                    if (isInbound == false)
                    {
                        throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                                 string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                               ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback
                        });
                    }

                    if (!ushort.TryParse(rawConfiguration[ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback], out maxConcurrentReceiveCallback))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = ServiceBusConfigurationKeys.MaxConcurrentReceiveCallback
                        });
                    }
                }
                else
                {
                    maxConcurrentReceiveCallback = Defaults.MaxConcurrentReceiveCallback;
                }

                sbSettings.MaxConcurrentReceiveCallback = maxConcurrentReceiveCallback;
                #endregion

                #region Return
                return(sbSettings);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, ServiceBusName);
                #endregion

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, ServiceBusName, logger: logger);
            }
        }
예제 #8
0
        /// <summary>
        /// Helper method to validate and collect RabbitMq parameters.
        /// </summary>
        public static RabbitMqConfiguration CollectConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Initialization
                var rabbitMqConfiguration = new RabbitMqConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();
                #endregion

                #region Collecting Common Configuration
                MessageQueueCommonItems.CollectCommonConfiguration(ref rawConfiguration, rabbitMqConfiguration, RabbitMqConfigurationKeys.GetAllKeys());
                #endregion

                #region Collecting Other Configuration
                // Port
                int port = 0;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.Port) &&
                    !int.TryParse(rawConfiguration[RabbitMqConfigurationKeys.Port], out port))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.Port),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.Port
                    });
                }

                rabbitMqConfiguration.Port = port;

                // UserName
                if (!rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.UserName) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[RabbitMqConfigurationKeys.UserName]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           RabbitMqConfigurationKeys.UserName),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.UserName
                    });
                }

                rabbitMqConfiguration.UserName = rawConfiguration[RabbitMqConfigurationKeys.UserName];

                // Password
                if (!rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.Password) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[RabbitMqConfigurationKeys.Password]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           RabbitMqConfigurationKeys.Password),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.Password
                    });
                }

                rabbitMqConfiguration.Password = rawConfiguration[RabbitMqConfigurationKeys.Password];

                // Queue Name
                if (!rawConfiguration.ContainsKey(CommonConfigurationKeys.QueueName) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[CommonConfigurationKeys.QueueName]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           CommonConfigurationKeys.QueueName),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = CommonConfigurationKeys.QueueName
                    });
                }

                rabbitMqConfiguration.QueueName = rawConfiguration[CommonConfigurationKeys.QueueName];

                // Exchange Name
                rabbitMqConfiguration.ExchangeName = null;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.ExchangeName))
                {
                    if (string.IsNullOrWhiteSpace(rawConfiguration[RabbitMqConfigurationKeys.ExchangeName]))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               RabbitMqConfigurationKeys.ExchangeName),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.ExchangeName
                        });
                    }

                    rabbitMqConfiguration.ExchangeName = rawConfiguration[RabbitMqConfigurationKeys.ExchangeName];
                }

                // Routing Key
                rabbitMqConfiguration.RoutingKey = null;

                if (rabbitMqConfiguration.ExchangeName == null &&
                    rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.RoutingKey))
                {
                    throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                             string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                           RabbitMqConfigurationKeys.RoutingKey),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.RoutingKey
                    });
                }

                if (rabbitMqConfiguration.ExchangeName != null)
                {
                    if (!rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.RoutingKey))
                    {
                        throw new QueueException(QueueErrorCode.ParameterRequiredInCurrentConfiguration,
                                                 string.Format(ErrorMessages.ParameterRequiredInCurrentConfiguration,
                                                               RabbitMqConfigurationKeys.RoutingKey),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.RoutingKey
                        });
                    }

                    rabbitMqConfiguration.RoutingKey = rawConfiguration[RabbitMqConfigurationKeys.RoutingKey];
                }

                // Durable Exchange
                var durableExchange = false;

                if (rabbitMqConfiguration.ExchangeName == null &&
                    rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.DurableExchange))
                {
                    throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                             string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                           RabbitMqConfigurationKeys.DurableExchange),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.DurableExchange
                    });
                }

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.DurableExchange) &&
                    !bool.TryParse(rawConfiguration[RabbitMqConfigurationKeys.DurableExchange], out durableExchange))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.DurableExchange),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.DurableExchange
                    });
                }

                rabbitMqConfiguration.DurableExchange = durableExchange;

                // Durable Queue
                var durableQueue = false;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.DurableQueue) &&
                    !bool.TryParse(rawConfiguration[RabbitMqConfigurationKeys.DurableQueue], out durableQueue))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.DurableQueue),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.DurableQueue
                    });
                }

                rabbitMqConfiguration.DurableQueue = durableQueue;

                // Durable Message
                var durableMessage = false;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.DurableMessage) &&
                    !bool.TryParse(rawConfiguration[RabbitMqConfigurationKeys.DurableMessage], out durableMessage))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.DurableMessage),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.DurableMessage
                    });
                }

                rabbitMqConfiguration.DurableMessage = durableMessage;

                // Acknowledgment
                var acknowledgment = false;

                if (isInbound == false && rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.Acknowledgment))
                {
                    throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                             string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                           RabbitMqConfigurationKeys.Acknowledgment),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.Acknowledgment
                    });
                }

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.Acknowledgment) &&
                    !bool.TryParse(rawConfiguration[RabbitMqConfigurationKeys.Acknowledgment], out acknowledgment))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.Acknowledgment),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.Acknowledgment
                    });
                }

                rabbitMqConfiguration.Acknowledgment = acknowledgment;

                // MaxConcurrentReceiveCallback
                ushort maxConcurrentReceiveCallback;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback))
                {
                    if (isInbound == false)
                    {
                        throw new QueueException(QueueErrorCode.ParameterNotApplicationInCurrentConfiguration,
                                                 string.Format(ErrorMessages.ParameterNotApplicationInCurrentConfiguration,
                                                               RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback
                        });
                    }

                    if (!ushort.TryParse(rawConfiguration[RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback],
                                         out maxConcurrentReceiveCallback))
                    {
                        throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                                 string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                               RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback),
                                                 context: new Dictionary <string, string>
                        {
                            [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.MaxConcurrentReceiveCallback
                        });
                    }
                }
                else
                {
                    maxConcurrentReceiveCallback = Defaults.MaxConcurrentReceiveCallback;
                }

                rabbitMqConfiguration.MaxConcurrentReceiveCallback = maxConcurrentReceiveCallback;

                // Connection Timeout
                var connectionTimeout = Defaults.RabbitMqConnectionTimeoutInMinutes;

                if (rawConfiguration.ContainsKey(RabbitMqConfigurationKeys.ConnectionTimeoutInMinutes) &&
                    !int.TryParse(rawConfiguration[RabbitMqConfigurationKeys.ConnectionTimeoutInMinutes],
                                  out connectionTimeout))
                {
                    throw new QueueException(QueueErrorCode.InvalidValueForConfigurationParameter,
                                             string.Format(ErrorMessages.InvalidValueForConfigurationParameter,
                                                           RabbitMqConfigurationKeys.ConnectionTimeoutInMinutes),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = RabbitMqConfigurationKeys.ConnectionTimeoutInMinutes
                    });
                }

                rabbitMqConfiguration.ConnectionTimeoutInMinutes = connectionTimeout;
                #endregion

                #region Return
                return(rabbitMqConfiguration);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, RabbitMqName);
                #endregion

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, RabbitMqName, logger: logger);
            }
        }