public SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ILogger <SubscriptionReceiver> logger) { this.settings = settings; this.topic = topic; this.subscription = subscription; this.processInParallel = processInParallel; this.logger = logger; this.client = new SubscriptionClient(settings.ConnectionString, topic, subscription); if (this.processInParallel) { this.client.PrefetchCount = 18; } else { this.client.PrefetchCount = 14; } dynamicThrottling = new DynamicThrottling( maxDegreeOfParallelism: 100, minDegreeOfParallelism: 50, penaltyAmount: 3, workFailedPenaltyAmount: 5, workCompletedParallelismGain: 1, intervalForRestoringDegreeOfParallelism: 8000); receiveRetryPolicy = Policy.Handle <Exception>().WaitAndRetryAsync(3, (r) => TimeSpan.FromMilliseconds(900),//, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)); (ex, ts, attemps, cc) => { this.dynamicThrottling.Penalize(); logger.LogWarning($"An error occurred in attempt number {attemps} to receive a message from subscription {subscription}: {ex.Message}"); }); }
/// <summary> /// Initializes a new instance of the <see cref="TopicSender"/> class, /// automatically creating the given topic if it does not exist. /// </summary> public TopicSender(ServiceBusSettings settings, string topic, ILogger <TopicSender> logger) { this.settings = settings; this.topic = topic; this.logger = logger; //TODO: verify how does it work. Was changed to newest version of ServiceBus library retryPolicy = Policy.Handle <Exception>(e => { logger.LogWarning( "An error occurred while sending message to the topic {1}: {0}", e.Message, topic); return(true); }) .WaitAndRetryAsync(4, retry => TimeSpan.FromSeconds(Math.Pow(2, retry))); topicClient = new TopicClient(settings.ConnectionString, topic); }
/// <summary> /// Initializes a new instance of the <see cref="SessionSubscriptionReceiver"/> class, /// automatically creating the topic and subscription if they don't exist. /// </summary> public SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ILogger <SessionSubscriptionReceiver> logger) { this.settings = settings; this.topic = topic; this.subscription = subscription; this.requiresSequentialProcessing = requiresSequentialProcessing; this.logger = logger; client = new SubscriptionClient(settings.ConnectionString, topic, subscription, ReceiveMode.PeekLock, Microsoft.Azure.ServiceBus.RetryPolicy.Default); if (this.requiresSequentialProcessing) { this.client.PrefetchCount = 10; } else { this.client.PrefetchCount = 15; } this.dynamicThrottling = new DynamicThrottling( maxDegreeOfParallelism: 160, minDegreeOfParallelism: 30, penaltyAmount: 3, workFailedPenaltyAmount: 5, workCompletedParallelismGain: 1, intervalForRestoringDegreeOfParallelism: 10000); this.receiveRetryPolicy = Policy.Handle <Exception>() .WaitAndRetryAsync(10, retry => TimeSpan.FromSeconds(Math.Pow(2, retry)), (ex, ts, attempt, context) => { this.dynamicThrottling.Penalize(); logger.LogWarning($"An error occurred in attempt number {attempt} to receive a message from subscription {subscription}: {ex.Message}"); }); }
public ServiceBusConfig(ServiceBusSettings settings, ILoggerFactory factory) { this.settings = settings; this.factory = factory; this.logger = factory.CreateLogger <ServiceBusConfig>(); }