|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 2.0. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v2.0: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 26 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 27 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 28 | +// |
| 29 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 30 | +//--------------------------------------------------------------------------- |
| 31 | + |
| 32 | +using System; |
| 33 | +using System.Threading.RateLimiting; |
| 34 | + |
| 35 | +namespace RabbitMQ.Client.Impl |
| 36 | +{ |
| 37 | + internal sealed class ChannelOptions |
| 38 | + { |
| 39 | + private readonly bool _publisherConfirmationEnabled; |
| 40 | + private readonly bool _publisherConfirmationTrackingEnabled; |
| 41 | + private readonly ushort _consumerDispatchConcurrency; |
| 42 | + private readonly RateLimiter? _outstandingPublisherConfirmationsRateLimiter; |
| 43 | + private readonly TimeSpan _continuationTimeout; |
| 44 | + |
| 45 | + public ChannelOptions(bool publisherConfirmationEnabled, |
| 46 | + bool publisherConfirmationTrackingEnabled, |
| 47 | + ushort consumerDispatchConcurrency, |
| 48 | + RateLimiter? outstandingPublisherConfirmationsRateLimiter, |
| 49 | + TimeSpan continuationTimeout) |
| 50 | + { |
| 51 | + _publisherConfirmationEnabled = publisherConfirmationEnabled; |
| 52 | + _publisherConfirmationTrackingEnabled = publisherConfirmationTrackingEnabled; |
| 53 | + _consumerDispatchConcurrency = consumerDispatchConcurrency; |
| 54 | + _outstandingPublisherConfirmationsRateLimiter = outstandingPublisherConfirmationsRateLimiter; |
| 55 | + _continuationTimeout = continuationTimeout; |
| 56 | + } |
| 57 | + |
| 58 | + public bool PublisherConfirmationsEnabled => _publisherConfirmationEnabled; |
| 59 | + |
| 60 | + public bool PublisherConfirmationTrackingEnabled => _publisherConfirmationTrackingEnabled; |
| 61 | + |
| 62 | + public ushort ConsumerDispatchConcurrency => _consumerDispatchConcurrency; |
| 63 | + |
| 64 | + public RateLimiter? OutstandingPublisherConfirmationsRateLimiter => _outstandingPublisherConfirmationsRateLimiter; |
| 65 | + |
| 66 | + public TimeSpan ContinuationTimeout => _continuationTimeout; |
| 67 | + |
| 68 | + public static ChannelOptions From(CreateChannelOptions createChannelOptions, |
| 69 | + ConnectionConfig connectionConfig) |
| 70 | + { |
| 71 | + ushort cdc = createChannelOptions.ConsumerDispatchConcurrency.GetValueOrDefault( |
| 72 | + connectionConfig.ConsumerDispatchConcurrency); |
| 73 | + |
| 74 | + return new ChannelOptions(createChannelOptions.PublisherConfirmationsEnabled, |
| 75 | + createChannelOptions.PublisherConfirmationTrackingEnabled, |
| 76 | + cdc, |
| 77 | + createChannelOptions.OutstandingPublisherConfirmationsRateLimiter, |
| 78 | + connectionConfig.ContinuationTimeout); |
| 79 | + } |
| 80 | + |
| 81 | + public static ChannelOptions From(ConnectionConfig connectionConfig) |
| 82 | + { |
| 83 | + return new ChannelOptions(publisherConfirmationEnabled: false, |
| 84 | + publisherConfirmationTrackingEnabled: false, |
| 85 | + consumerDispatchConcurrency: Constants.DefaultConsumerDispatchConcurrency, |
| 86 | + outstandingPublisherConfirmationsRateLimiter: null, |
| 87 | + continuationTimeout: connectionConfig.ContinuationTimeout); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments