29
29
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
30
30
//---------------------------------------------------------------------------
31
31
32
+ using System ;
32
33
using System . Threading . RateLimiting ;
33
34
34
35
namespace RabbitMQ . Client
@@ -38,6 +39,9 @@ namespace RabbitMQ.Client
38
39
/// </summary>
39
40
public sealed class CreateChannelOptions
40
41
{
42
+ private ushort ? _connectionConfigConsumerDispatchConcurrency ;
43
+ private TimeSpan _connectionConfigContinuationTimeout ;
44
+
41
45
/// <summary>
42
46
/// Enable or disable publisher confirmations on this channel. Defaults to <c>false</c>
43
47
///
@@ -49,7 +53,7 @@ public sealed class CreateChannelOptions
49
53
/// <see cref="IChannel.GetNextPublishSequenceNumberAsync(System.Threading.CancellationToken)"/> to allow correlation
50
54
/// of the response with the correct message.
51
55
/// </summary>
52
- public bool PublisherConfirmationsEnabled { get ; set ; } = false ;
56
+ public readonly bool PublisherConfirmationsEnabled = false ;
53
57
54
58
/// <summary>
55
59
/// Should this library track publisher confirmations for you? Defaults to <c>false</c>
@@ -59,7 +63,7 @@ public sealed class CreateChannelOptions
59
63
/// If the broker then sends a <c>basic.return</c> response for the message, this library can
60
64
/// then correctly handle the message.
61
65
/// </summary>
62
- public bool PublisherConfirmationTrackingEnabled { get ; set ; } = false ;
66
+ public readonly bool PublisherConfirmationTrackingEnabled = false ;
63
67
64
68
/// <summary>
65
69
/// If the publisher confirmation tracking is enabled, this represents the rate limiter used to
@@ -68,7 +72,7 @@ public sealed class CreateChannelOptions
68
72
/// Defaults to a <see cref="ThrottlingRateLimiter"/> with a limit of 128 and a throttling percentage of 50% with a delay during throttling.
69
73
/// </summary>
70
74
/// <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 ) ;
72
76
73
77
/// <summary>
74
78
/// 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
80
84
/// For concurrency greater than one this removes the guarantee that consumers handle messages in the order they receive them.
81
85
/// In addition to that consumers need to be thread/concurrency safe.
82
86
/// </summary>
83
- public ushort ? ConsumerDispatchConcurrency { get ; set ; } = null ;
87
+ public readonly ushort ? ConsumerDispatchConcurrency = null ;
84
88
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
+ }
89
144
}
90
145
}
0 commit comments