2929// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
3030//---------------------------------------------------------------------------
3131
32+ using System ;
3233using System . Threading . RateLimiting ;
3334
3435namespace RabbitMQ . Client
@@ -38,6 +39,9 @@ namespace RabbitMQ.Client
3839 /// </summary>
3940 public sealed class CreateChannelOptions
4041 {
42+ private ushort ? _connectionConfigConsumerDispatchConcurrency ;
43+ private TimeSpan _connectionConfigContinuationTimeout ;
44+
4145 /// <summary>
4246 /// Enable or disable publisher confirmations on this channel. Defaults to <c>false</c>
4347 ///
@@ -49,7 +53,7 @@ public sealed class CreateChannelOptions
4953 /// <see cref="IChannel.GetNextPublishSequenceNumberAsync(System.Threading.CancellationToken)"/> to allow correlation
5054 /// of the response with the correct message.
5155 /// </summary>
52- public bool PublisherConfirmationsEnabled { get ; set ; } = false ;
56+ public readonly bool PublisherConfirmationsEnabled = false ;
5357
5458 /// <summary>
5559 /// Should this library track publisher confirmations for you? Defaults to <c>false</c>
@@ -59,7 +63,7 @@ public sealed class CreateChannelOptions
5963 /// If the broker then sends a <c>basic.return</c> response for the message, this library can
6064 /// then correctly handle the message.
6165 /// </summary>
62- public bool PublisherConfirmationTrackingEnabled { get ; set ; } = false ;
66+ public readonly bool PublisherConfirmationTrackingEnabled = false ;
6367
6468 /// <summary>
6569 /// If the publisher confirmation tracking is enabled, this represents the rate limiter used to
@@ -68,7 +72,7 @@ public sealed class CreateChannelOptions
6872 /// Defaults to a <see cref="ThrottlingRateLimiter"/> with a limit of 128 and a throttling percentage of 50% with a delay during throttling.
6973 /// </summary>
7074 /// <remarks>Setting the rate limiter to <c>null</c> disables the rate limiting entirely.</remarks>
71- public RateLimiter ? OutstandingPublisherConfirmationsRateLimiter { get ; set ; } = new ThrottlingRateLimiter ( 128 ) ;
75+ public readonly RateLimiter ? OutstandingPublisherConfirmationsRateLimiter = new ThrottlingRateLimiter ( 128 ) ;
7276
7377 /// <summary>
7478 /// Set to a value greater than one to enable concurrent processing. For a concurrency greater than one <see cref="IAsyncBasicConsumer"/>
@@ -80,11 +84,62 @@ public sealed class CreateChannelOptions
8084 /// For concurrency greater than one this removes the guarantee that consumers handle messages in the order they receive them.
8185 /// In addition to that consumers need to be thread/concurrency safe.
8286 /// </summary>
83- public ushort ? ConsumerDispatchConcurrency { get ; set ; } = null ;
87+ public readonly ushort ? ConsumerDispatchConcurrency = null ;
8488
85- /// <summary>
86- /// The default channel options.
87- /// </summary>
88- public static CreateChannelOptions Default { get ; } = new CreateChannelOptions ( ) ;
89+ public CreateChannelOptions ( bool publisherConfirmationsEnabled ,
90+ bool publisherConfirmationTrackingEnabled ,
91+ RateLimiter ? outstandingPublisherConfirmationsRateLimiter = null ,
92+ ushort ? consumerDispatchConcurrency = Constants . DefaultConsumerDispatchConcurrency )
93+ {
94+ PublisherConfirmationsEnabled = publisherConfirmationsEnabled ;
95+ PublisherConfirmationTrackingEnabled = publisherConfirmationTrackingEnabled ;
96+ OutstandingPublisherConfirmationsRateLimiter = outstandingPublisherConfirmationsRateLimiter ;
97+ ConsumerDispatchConcurrency = consumerDispatchConcurrency ;
98+ }
99+
100+ internal ushort InternalConsumerDispatchConcurrency
101+ {
102+ get
103+ {
104+ if ( ConsumerDispatchConcurrency is not null )
105+ {
106+ return ConsumerDispatchConcurrency . Value ;
107+ }
108+
109+ if ( _connectionConfigConsumerDispatchConcurrency is not null )
110+ {
111+ return _connectionConfigConsumerDispatchConcurrency . Value ;
112+ }
113+
114+ return Constants . DefaultConsumerDispatchConcurrency ;
115+ }
116+ }
117+
118+ internal TimeSpan ContinuationTimeout => _connectionConfigContinuationTimeout ;
119+
120+ internal CreateChannelOptions ( ConnectionConfig connectionConfig )
121+ {
122+ _connectionConfigConsumerDispatchConcurrency = connectionConfig . ConsumerDispatchConcurrency ;
123+ _connectionConfigContinuationTimeout = connectionConfig . ContinuationTimeout ;
124+ }
125+
126+ private CreateChannelOptions WithConnectionConfig ( ConnectionConfig connectionConfig )
127+ {
128+ _connectionConfigConsumerDispatchConcurrency = connectionConfig . ConsumerDispatchConcurrency ;
129+ _connectionConfigContinuationTimeout = connectionConfig . ContinuationTimeout ;
130+ return this ;
131+ }
132+
133+ internal static CreateChannelOptions CreateOrUpdate ( CreateChannelOptions ? createChannelOptions , ConnectionConfig config )
134+ {
135+ if ( createChannelOptions is null )
136+ {
137+ return new CreateChannelOptions ( config ) ;
138+ }
139+ else
140+ {
141+ return createChannelOptions . WithConnectionConfig ( config ) ;
142+ }
143+ }
89144 }
90145}
0 commit comments