/// <summary> /// Compares retry options between two instances to determine if the /// instances represent the same set of options. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// <param name="other">The other set of retry options to consider.</param> /// /// <returns><c>true</c>, if the two sets of options are structurally equivalent; otherwise, <c>false</c>.</returns> /// public static bool IsEquivalentTo( this ServiceBusRetryOptions instance, ServiceBusRetryOptions other) { // If the events are the same instance, they're equal. This should only happen // if both are null or they are the exact same instance. if (Object.ReferenceEquals(instance, other)) { return(true); } // If one or the other is null, then they cannot be equal, since we know that // they are not both null. if ((instance == null) || (other == null)) { return(false); } // If the contents of each attribute are equal, the instance are // equal. return ( instance.Mode == other.Mode && instance.MaximumRetries == other.MaximumRetries && instance.Delay == other.Delay && instance.MaximumDelay == other.MaximumDelay && instance.TryTimeout == other.TryTimeout && instance.CustomRetryPolicy == other.CustomRetryPolicy ); }
public void CalulateTryTimeoutRespectsOptions(int attemptCount) { var timeout = TimeSpan.FromSeconds(5); var options = new ServiceBusRetryOptions { TryTimeout = timeout }; var policy = new BasicRetryPolicy(options); Assert.That(policy.CalculateTryTimeout(attemptCount), Is.EqualTo(options.TryTimeout)); }
/// <summary> /// Creates a new copy of the current <see cref="ServiceBusRetryOptions" />, cloning its attributes into a new instance. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// /// <returns>A new copy of <see cref="ServiceBusRetryOptions" />.</returns> /// public static ServiceBusRetryOptions Clone(this ServiceBusRetryOptions instance) => new ServiceBusRetryOptions { Mode = instance.Mode, CustomRetryPolicy = instance.CustomRetryPolicy, MaximumRetries = instance.MaximumRetries, Delay = instance.Delay, MaximumDelay = instance.MaximumDelay, TryTimeout = instance.TryTimeout };
protected ServiceBusClient GetClient(int tryTimeout = 15) { var retryOptions = new ServiceBusRetryOptions(); if (tryTimeout != default) { retryOptions.TryTimeout = TimeSpan.FromSeconds(tryTimeout); } return(new ServiceBusClient( TestEnvironment.ServiceBusConnectionString, new ServiceBusClientOptions { RetryOptions = retryOptions })); }
/// <summary> /// Initializes a new instance of the <see cref="BasicRetryPolicy"/> class. /// </summary> /// /// <param name="retryOptions">The options which control the retry approach.</param> /// public BasicRetryPolicy(ServiceBusRetryOptions retryOptions) { Argument.AssertNotNull(retryOptions, nameof(retryOptions)); Options = retryOptions; }
public static TransportExtensions <AzureServiceBusTransport> CustomRetryPolicy(this TransportExtensions <AzureServiceBusTransport> transportExtensions, ServiceBusRetryOptions retryPolicy) { Guard.AgainstNull(nameof(retryPolicy), retryPolicy); transportExtensions.Transport.RetryPolicyOptions = retryPolicy; return(transportExtensions); }
/// <summary> /// Converts the options into a retry policy for use. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// /// <returns>The <see cref="ServiceBusRetryPolicy" /> represented by the options.</returns> public static ServiceBusRetryPolicy ToRetryPolicy(this ServiceBusRetryOptions instance) => instance.CustomRetryPolicy ?? new BasicRetryPolicy(instance);