source/TestCommon/source/FunctionApp.TestCommon/ServiceBus/ListenerMock/ServiceBusListenerMock.cs
/// <summary>
/// Add a listener for a given topic/subscription path.
/// The listener starts reading messages instantly when added.
/// </summary>
/// <param name="topicName">Name of the topic.</param>
/// <param name="subscriptionName">Name of the subscription.</param>
Add a listener for a given topic/subscription path.
The listener starts reading messages instantly when added.
Add a listener for a given topic / subscription path . The listener starts reading messages instantly when added .
public async Task AddTopicSubscriptionListenerAsync(string topicName, string subscriptionName)
        {
            if (string.IsNullOrWhiteSpace(topicName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(topicName));
            }
            if (string.IsNullOrWhiteSpace(subscriptionName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(subscriptionName));
            }
            if (!await AdministrationClient.SubscriptionExistsAsync(topicName, subscriptionName).ConfigureAwait(false))
            {
                throw new InvalidOperationException($"Topic '{topicName}' with subscription '{subscriptionName}' does not exists.");
            }
            var options = CreateDefaultProcessorOptions();
            var receiver = Client.CreateProcessor(topicName, subscriptionName, options);
            await AddMessageReceiverAsync($"{topicName}-{subscriptionName}", receiver).ConfigureAwait(false);
        }
public async Task AddTopicSubscriptionListenerAsync ( string topicName , string subscriptionName ) { if ( string . IsNullOrWhiteSpace ( topicName ) ) { throw new ArgumentException ( " " , nameof ( topicName ) ) ; } if ( string . IsNullOrWhiteSpace ( subscriptionName ) ) { throw new ArgumentException ( " " , nameof ( subscriptionName ) ) ; } if ( ! await AdministrationClient . SubscriptionExistsAsync ( topicName , subscriptionName ) . ConfigureAwait ( false ) ) { throw new InvalidOperationException ( $" Topic ' { topicName } ' with subscription ' { subscriptionName } ' does not exists. " ) ; } var options = CreateDefaultProcessorOptions ( ) ; var receiver = Client . CreateProcessor ( topicName , subscriptionName , options ) ; await AddMessageReceiverAsync ( $" { topicName } - { subscriptionName } " , receiver ) . ConfigureAwait ( false ) ; }
Add a listener for a given topic/subscription path.
Add a listener for a given topic / subscription path .
topicName
string
Name of the topic.
Name of the topic .
subscriptionName
string
Name of the subscription.
Name of the subscription .