Exemplo n.º 1
0
 private void EnsureSubscription()
 {
     if (_managementClientWrapper.SubscriptionExists(_topicName, _subscriptionName))
     {
         return;
     }
     try
     {
         _managementClientWrapper.CreateSubscription(_topicName, _subscriptionName);
     }
     catch (MessagingEntityAlreadyExistsException)
     {
     }
 }
Exemplo n.º 2
0
        private void EnsureSubscription()
        {
            const int maxDeliveryCount = 2000;

            if (_subscriptionCreated || _makeChannel.Equals(OnMissingChannel.Assume))
            {
                return;
            }

            try
            {
                if (_managementClientWrapper.SubscriptionExists(_topicName, _subscriptionName))
                {
                    _subscriptionCreated = true;
                    return;
                }

                if (_makeChannel.Equals(OnMissingChannel.Validate))
                {
                    throw new ChannelFailureException($"Subscription {_subscriptionName} does not exist on topic {_topicName} and missing channel mode set to Validate.");
                }

                _managementClientWrapper.CreateSubscription(_topicName, _subscriptionName, maxDeliveryCount);
                _subscriptionCreated = true;
            }
            catch (MessagingEntityAlreadyExistsException)
            {
                s_logger.LogWarning("Message entity already exists with topic {Topic} and subscription {ChannelName}.", _topicName,
                                    _subscriptionName);
                _subscriptionCreated = true;
            }
            catch (Exception e)
            {
                s_logger.LogError(e, "Failing to check or create subscription.");

                //The connection to Azure Service bus may have failed so we re-establish the connection.
                _managementClientWrapper.Reset();

                throw new ChannelFailureException("Failing to check or create subscription", e);
            }
        }