Exemplo n.º 1
0
        ///  <summary>
        ///      Sets Up primary Service Bus connection.
        ///      Sets Up Secondary Service Bus connection if secondary connection string exists.
        ///      Sets Up Retry and Fallback policies if secondary connection string exists.
        ///         Logs Exception in case of failure in secondary namespace
        ///  </summary>
        /// <param name="options"></param>
        public Messaging(IOptions <MessagingOptions> options)
        {
            var _options = options.Value;

            MessageFactory.PrimarySenderClient =
                MessageFactory.SetUpFactory(_options.TopicName, _options.ServiceBusConnectionString, RetryPolicy.Default);

            if (string.IsNullOrEmpty(_options.ServiceBusConnectionStringSecondary))
            {
                return;
            }

            MessageFactory.SecondarySenderClient =
                MessageFactory.SetUpFactory(_options.TopicName, _options.ServiceBusConnectionStringSecondary, RetryPolicy.Default);

            MessageFactory.ErrorSenderClient =
                MessageFactory.SetUpFactory(_options.ErrorQueueName, _options.ServiceBusConnectionStringSecondary);

            PollyFactory.SetUpPolicies(_options.RetryCount, _options.RetrySeconds, OnFallBackAction, OnErrorAction);
        }
Exemplo n.º 2
0
        ///  <summary>
        ///      Sets Up primary Service Bus connection.
        ///      Sets Up Secondary Service Bus connection if secondary connection string exists.
        ///      Sets Up Retry and Fallback policies if secondary connection string exists.
        ///         Logs Exception in case of failure in secondary namespace
        ///  </summary>
        ///  <param name="topicName">Service Bus topic name</param>
        ///  <param name="connectionStringPrimary">Service Bus primary connection string</param>
        ///  <param name="connectionStringSecondary">Service Bus secondary connection string</param>
        ///  <param name="retryCount">Number of retries applied to Retry Policy</param>
        ///  <param name="retrySeconds">Number of seconds between every retry</param>
        ///  <param name="errorQueueName">Name of Queue to log expections</param>
        public Messaging(
            string topicName,
            string connectionStringPrimary, string connectionStringSecondary = "",
            int retryCount = RetryCount, int retrySeconds = RetrySeconds, string errorQueueName = ErrorQueueName)
        {
            MessageFactory.PrimarySenderClient =
                MessageFactory.SetUpFactory(topicName, connectionStringPrimary, RetryPolicy.Default);

            if (string.IsNullOrEmpty(connectionStringSecondary))
            {
                return;
            }

            MessageFactory.SecondarySenderClient =
                MessageFactory.SetUpFactory(topicName, connectionStringSecondary, RetryPolicy.Default);

            MessageFactory.ErrorSenderClient =
                MessageFactory.SetUpFactory(errorQueueName, connectionStringSecondary);

            PollyFactory.SetUpPolicies(retryCount, retrySeconds, OnFallBackAction, OnErrorAction);
        }