@@ -38,18 +38,6 @@ public sealed class PubSubPerformanceConfig
3838 /// </summary>
3939 public TimeSpan ShutdownTimeout { get ; set ; } = TimeSpan . FromSeconds ( DefaultShutdownTimeoutSeconds ) ;
4040
41- /// <summary>
42- /// Enable performance metrics logging.
43- /// Default: false
44- /// </summary>
45- public bool EnableMetrics { get ; set ; } = false ;
46-
47- /// <summary>
48- /// Interval for logging performance metrics.
49- /// Default: 30 seconds
50- /// </summary>
51- public TimeSpan MetricsInterval { get ; set ; } = TimeSpan . FromSeconds ( 30 ) ;
52-
5341 /// <summary>
5442 /// Validates the configuration.
5543 /// </summary>
@@ -66,127 +54,9 @@ internal void Validate()
6654 throw new ArgumentOutOfRangeException ( nameof ( ShutdownTimeout ) , "Shutdown timeout must be greater than zero" ) ;
6755 }
6856
69- if ( EnableMetrics && MetricsInterval <= TimeSpan . Zero )
70- {
71- throw new ArgumentOutOfRangeException ( nameof ( MetricsInterval ) , "Metrics interval must be greater than zero when metrics are enabled" ) ;
72- }
73-
7457 if ( ! Enum . IsDefined ( typeof ( BoundedChannelFullMode ) , FullMode ) )
7558 {
7659 throw new ArgumentOutOfRangeException ( nameof ( FullMode ) , "Invalid BoundedChannelFullMode value" ) ;
7760 }
7861 }
7962}
80-
81- /// <summary>
82- /// Extension methods for configuring PubSub performance options.
83- /// </summary>
84- public static class PubSubConfigurationExtensions
85- {
86- /// <summary>
87- /// Configure performance options for PubSub message processing.
88- /// </summary>
89- /// <typeparam name="T">The configuration type.</typeparam>
90- /// <param name="config">The PubSub subscription configuration.</param>
91- /// <param name="performanceConfig">The performance configuration to apply.</param>
92- /// <returns>The configuration instance for method chaining.</returns>
93- /// <exception cref="ArgumentNullException">Thrown when performanceConfig is null.</exception>
94- public static T WithPerformanceConfig < T > ( this T config , PubSubPerformanceConfig performanceConfig )
95- where T : BasePubSubSubscriptionConfig
96- {
97- ArgumentNullException . ThrowIfNull ( performanceConfig ) ;
98- performanceConfig . Validate ( ) ;
99-
100- config . PerformanceConfig = performanceConfig ;
101- return config ;
102- }
103-
104- /// <summary>
105- /// Configure channel capacity for PubSub message queuing.
106- /// </summary>
107- /// <typeparam name="T">The configuration type.</typeparam>
108- /// <param name="config">The PubSub subscription configuration.</param>
109- /// <param name="capacity">The maximum number of messages to queue.</param>
110- /// <returns>The configuration instance for method chaining.</returns>
111- /// <exception cref="ArgumentOutOfRangeException">Thrown when capacity is less than or equal to zero.</exception>
112- public static T WithChannelCapacity < T > ( this T config , int capacity )
113- where T : BasePubSubSubscriptionConfig
114- {
115- if ( capacity <= 0 )
116- {
117- throw new ArgumentOutOfRangeException ( nameof ( capacity ) , "Channel capacity must be greater than zero" ) ;
118- }
119-
120- config . PerformanceConfig ??= new PubSubPerformanceConfig ( ) ;
121- config . PerformanceConfig . ChannelCapacity = capacity ;
122- return config ;
123- }
124-
125- /// <summary>
126- /// Configure the backpressure strategy when the message channel is full.
127- /// </summary>
128- /// <typeparam name="T">The configuration type.</typeparam>
129- /// <param name="config">The PubSub subscription configuration.</param>
130- /// <param name="fullMode">The strategy to use when the channel is full.</param>
131- /// <returns>The configuration instance for method chaining.</returns>
132- public static T WithFullMode < T > ( this T config , BoundedChannelFullMode fullMode )
133- where T : BasePubSubSubscriptionConfig
134- {
135- if ( ! Enum . IsDefined ( typeof ( BoundedChannelFullMode ) , fullMode ) )
136- {
137- throw new ArgumentOutOfRangeException ( nameof ( fullMode ) , "Invalid BoundedChannelFullMode value" ) ;
138- }
139-
140- config . PerformanceConfig ??= new PubSubPerformanceConfig ( ) ;
141- config . PerformanceConfig . FullMode = fullMode ;
142- return config ;
143- }
144-
145- /// <summary>
146- /// Configure the shutdown timeout for graceful PubSub processing termination.
147- /// </summary>
148- /// <typeparam name="T">The configuration type.</typeparam>
149- /// <param name="config">The PubSub subscription configuration.</param>
150- /// <param name="timeout">The timeout duration.</param>
151- /// <returns>The configuration instance for method chaining.</returns>
152- /// <exception cref="ArgumentOutOfRangeException">Thrown when timeout is less than or equal to zero.</exception>
153- public static T WithShutdownTimeout < T > ( this T config , TimeSpan timeout )
154- where T : BasePubSubSubscriptionConfig
155- {
156- if ( timeout <= TimeSpan . Zero )
157- {
158- throw new ArgumentOutOfRangeException ( nameof ( timeout ) , "Shutdown timeout must be greater than zero" ) ;
159- }
160-
161- config . PerformanceConfig ??= new PubSubPerformanceConfig ( ) ;
162- config . PerformanceConfig . ShutdownTimeout = timeout ;
163- return config ;
164- }
165-
166- /// <summary>
167- /// Enable performance metrics logging with optional custom interval.
168- /// </summary>
169- /// <typeparam name="T">The configuration type.</typeparam>
170- /// <param name="config">The PubSub subscription configuration.</param>
171- /// <param name="interval">The interval for logging metrics. If null, uses default of 30 seconds.</param>
172- /// <returns>The configuration instance for method chaining.</returns>
173- /// <exception cref="ArgumentOutOfRangeException">Thrown when interval is less than or equal to zero.</exception>
174- public static T WithMetrics < T > ( this T config , TimeSpan ? interval = null )
175- where T : BasePubSubSubscriptionConfig
176- {
177- if ( interval . HasValue && interval . Value <= TimeSpan . Zero )
178- {
179- throw new ArgumentOutOfRangeException ( nameof ( interval ) , "Metrics interval must be greater than zero" ) ;
180- }
181-
182- config . PerformanceConfig ??= new PubSubPerformanceConfig ( ) ;
183- config . PerformanceConfig . EnableMetrics = true ;
184-
185- if ( interval . HasValue )
186- {
187- config . PerformanceConfig . MetricsInterval = interval . Value ;
188- }
189-
190- return config ;
191- }
192- }
0 commit comments