< Summary

Class:Microsoft.Azure.ServiceBus.MessageHandlerOptions
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\MessageHandlerOptions.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:96
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_ExceptionReceivedHandler()-0%100%
get_MaxConcurrentCalls()-0%100%
set_MaxConcurrentCalls(...)-0%0%
get_AutoComplete()-0%100%
get_MaxAutoRenewDuration()-0%100%
set_MaxAutoRenewDuration(...)-0%100%
get_AutoRenewLock()-0%100%
get_ReceiveTimeOut()-0%100%
RaiseExceptionReceived()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\MessageHandlerOptions.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus
 5{
 6    using Primitives;
 7    using System;
 8    using System.Threading;
 9    using System.Threading.Tasks;
 10
 11    /// <summary>Provides options associated with message pump processing using
 12    /// <see cref="QueueClient.RegisterMessageHandler(Func{Message, CancellationToken, Task}, MessageHandlerOptions)" />
 13    /// <see cref="SubscriptionClient.RegisterMessageHandler(Func{Message, CancellationToken, Task}, MessageHandlerOptio
 14    public sealed class MessageHandlerOptions
 15    {
 16        int maxConcurrentCalls;
 17        TimeSpan maxAutoRenewDuration;
 18
 19        /// <summary>Initializes a new instance of the <see cref="MessageHandlerOptions" /> class.
 20        /// Default Values:
 21        ///     <see cref="MaxConcurrentCalls"/> = 1
 22        ///     <see cref="AutoComplete"/> = true
 23        ///     <see cref="ReceiveTimeOut"/> = 1 minute
 24        ///     <see cref="MaxAutoRenewDuration"/> = 5 minutes
 25        /// </summary>
 26        /// <param name="exceptionReceivedHandler">A <see cref="Func{T1, TResult}"/> that is invoked during exceptions.
 27        /// <see cref="ExceptionReceivedEventArgs"/> contains contextual information regarding the exception.</param>
 028        public MessageHandlerOptions(Func<ExceptionReceivedEventArgs, Task> exceptionReceivedHandler)
 29        {
 030            this.MaxConcurrentCalls = 1;
 031            this.AutoComplete = true;
 032            this.ReceiveTimeOut = Constants.DefaultOperationTimeout;
 033            this.MaxAutoRenewDuration = Constants.ClientPumpRenewLockTimeout;
 034            this.ExceptionReceivedHandler = exceptionReceivedHandler ?? throw new ArgumentNullException(nameof(exception
 035        }
 36
 37        /// <summary>Occurs when an exception is received. Enables you to be notified of any errors encountered by the m
 38        /// When errors are received calls will automatically be retried, so this is informational. </summary>
 039        public Func<ExceptionReceivedEventArgs, Task> ExceptionReceivedHandler { get; }
 40
 41        /// <summary>Gets or sets the maximum number of concurrent calls to the callback the message pump should initiat
 42        /// <value>The maximum number of concurrent calls to the callback.</value>
 43        public int MaxConcurrentCalls
 44        {
 045            get => this.maxConcurrentCalls;
 46
 47            set
 48            {
 049                if (value <= 0)
 50                {
 051                    throw new ArgumentOutOfRangeException(Resources.MaxConcurrentCallsMustBeGreaterThanZero.FormatForUse
 52                }
 53
 054                this.maxConcurrentCalls = value;
 055            }
 56        }
 57
 58        /// <summary>Gets or sets a value that indicates whether the message-pump should call
 59        /// <see cref="QueueClient.CompleteAsync(string)" /> or
 60        /// <see cref="SubscriptionClient.CompleteAsync(string)" /> on messages after the callback has completed process
 61        /// <value>true to complete the message processing automatically on successful execution of the operation; other
 062        public bool AutoComplete { get; set; }
 63
 64        /// <summary>Gets or sets the maximum duration within which the lock will be renewed automatically. This
 65        /// value should be greater than the longest message lock duration; for example, the LockDuration Property. </su
 66        /// <value>The maximum duration during which locks are automatically renewed.</value>
 67        /// <remarks>The message renew can continue for sometime in the background
 68        /// after completion of message and result in a few false MessageLockLostExceptions temporarily.</remarks>
 69        public TimeSpan MaxAutoRenewDuration
 70        {
 071            get => this.maxAutoRenewDuration;
 72
 73            set
 74            {
 075                TimeoutHelper.ThrowIfNegativeArgument(value, nameof(value));
 076                this.maxAutoRenewDuration = value;
 077            }
 78        }
 79
 080        internal bool AutoRenewLock => this.MaxAutoRenewDuration > TimeSpan.Zero;
 81
 082        internal TimeSpan ReceiveTimeOut { get; }
 83
 84        internal async Task RaiseExceptionReceived(ExceptionReceivedEventArgs eventArgs)
 85        {
 86            try
 87            {
 088                await this.ExceptionReceivedHandler(eventArgs).ConfigureAwait(false);
 089            }
 090            catch (Exception exception)
 91            {
 092                MessagingEventSource.Log.ExceptionReceivedHandlerThrewException(exception);
 093            }
 094        }
 95    }
 96}