@@ -76,8 +76,7 @@ public IConsumerBuilder SubscriptionListener(Action<IConsumerBuilder.ListenerCon
7676
7777 public IConsumerBuilder . IStreamOptions Stream ( )
7878 {
79- return new ConsumerBuilderStreamOptions ( this , _configuration . Filters ,
80- _amqpConnection . _featureFlags ) ;
79+ return new ConsumerBuilderStreamOptions ( this , _configuration . Filters ) ;
8180 }
8281
8382 public async Task < IConsumer > BuildAndStartAsync ( CancellationToken cancellationToken = default )
@@ -87,6 +86,13 @@ public async Task<IConsumer> BuildAndStartAsync(CancellationToken cancellationTo
8786 throw new ConsumerException ( "Message handler is not set" ) ;
8887 }
8988
89+ if ( _configuration . Filters [ Consts . SqlFilter ] is not null &&
90+ _amqpConnection . _featureFlags . IsSqlFeatureEnabled == false )
91+ {
92+ throw new ConsumerException ( "SQL filter is not supported by the connection." +
93+ "RabbitMQ 4.2.0 or later is required." ) ;
94+ }
95+
9096 AmqpConsumer consumer = new ( _amqpConnection , _configuration , _metricsReporter ) ;
9197
9298 // TODO pass cancellationToken
@@ -107,34 +113,18 @@ public abstract class StreamOptions : IConsumerBuilder.IStreamOptions
107113 private static readonly Regex s_offsetValidator = new Regex ( "^[0-9]+[YMDhms]$" ,
108114 RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
109115
110- // sql-filter
111- private const string SqlFilter = "sql-filter" ;
112- private const string RmqStreamFilter = "rabbitmq:stream-filter" ;
113- private const string RmqStreamOffsetSpec = "rabbitmq:stream-offset-spec" ;
114-
115- private const string RmqStreamMatchUnfiltered = "rabbitmq:stream-match-unfiltered" ;
116-
117- // amqp:sql-filter
118- private const string AmqpSqlFilter = "amqp:sql-filter" ;
119-
120- private static readonly Symbol s_streamFilterSymbol = new ( RmqStreamFilter ) ;
121- private static readonly Symbol s_streamOffsetSpecSymbol = new ( RmqStreamOffsetSpec ) ;
122- private static readonly Symbol s_streamMatchUnfilteredSymbol = new ( RmqStreamMatchUnfiltered ) ;
123- private static readonly Symbol s_streamSqlFilterSymbol = new ( AmqpSqlFilter ) ;
124116
125117 private readonly Map _filters ;
126- private readonly FeatureFlags _featureFlags ;
127118
128- protected StreamOptions ( Map filters , FeatureFlags featureFlags )
119+ protected StreamOptions ( Map filters )
129120 {
130121 _filters = filters ;
131- _featureFlags = featureFlags ;
132122 }
133123
134124 public IConsumerBuilder . IStreamOptions Offset ( long offset )
135125 {
136- _filters [ s_streamOffsetSpecSymbol ] =
137- new DescribedValue ( s_streamOffsetSpecSymbol , offset ) ;
126+ _filters [ Consts . s_streamOffsetSpecSymbol ] =
127+ new DescribedValue ( Consts . s_streamOffsetSpecSymbol , offset ) ;
138128 return this ;
139129 }
140130
@@ -168,42 +158,25 @@ public IConsumerBuilder.IStreamOptions Offset(string interval)
168158
169159 public IConsumerBuilder . IStreamOptions FilterValues ( params string [ ] values )
170160 {
171- _filters [ s_streamFilterSymbol ] =
172- new DescribedValue ( s_streamFilterSymbol , values . ToList ( ) ) ;
161+ _filters [ Consts . s_streamFilterSymbol ] =
162+ new DescribedValue ( Consts . s_streamFilterSymbol , values . ToList ( ) ) ;
173163 return this ;
174164 }
175165
176166 public IConsumerBuilder . IStreamOptions FilterMatchUnfiltered ( bool matchUnfiltered )
177167 {
178- _filters [ s_streamMatchUnfilteredSymbol ]
179- = new DescribedValue ( s_streamMatchUnfilteredSymbol , matchUnfiltered ) ;
168+ _filters [ Consts . s_streamMatchUnfilteredSymbol ]
169+ = new DescribedValue ( Consts . s_streamMatchUnfilteredSymbol , matchUnfiltered ) ;
180170 return this ;
181171 }
182172
183- public IConsumerBuilder . IStreamFilterOptions Sql ( string sql )
184- {
185- if ( string . IsNullOrWhiteSpace ( sql ) )
186- {
187- throw new ArgumentNullException ( nameof ( sql ) ) ;
188- }
189-
190- if ( false == _featureFlags . IsSqlFeatureEnabled )
191- {
192- throw new ConsumerException ( "SQL filter is not supported by the broker. " +
193- "The broker must be RabbitMQ 4.2 or later." ) ;
194- }
195-
196- _filters [ SqlFilter ] =
197- new DescribedValue ( s_streamSqlFilterSymbol , sql ) ;
198- return Filter ( ) ;
199- }
200173
201174 public abstract IConsumerBuilder Builder ( ) ;
202175
203176 private void SetOffsetSpecificationFilter ( object value )
204177 {
205- _filters [ s_streamOffsetSpecSymbol ]
206- = new DescribedValue ( s_streamOffsetSpecSymbol , value ) ;
178+ _filters [ Consts . s_streamOffsetSpecSymbol ]
179+ = new DescribedValue ( Consts . s_streamOffsetSpecSymbol , value ) ;
207180 }
208181
209182 public IConsumerBuilder . IStreamFilterOptions Filter ( )
@@ -226,8 +199,8 @@ public IConsumerBuilder.IStreamFilterOptions Filter()
226199 /// </summary>
227200 public class ListenerStreamOptions : StreamOptions
228201 {
229- public ListenerStreamOptions ( Map filters , FeatureFlags featureFlags )
230- : base ( filters , featureFlags )
202+ public ListenerStreamOptions ( Map filters )
203+ : base ( filters )
231204 {
232205 }
233206
@@ -249,8 +222,8 @@ public class ConsumerBuilderStreamOptions : StreamOptions
249222 private readonly IConsumerBuilder _consumerBuilder ;
250223
251224 public ConsumerBuilderStreamOptions ( IConsumerBuilder consumerBuilder ,
252- Map filters , FeatureFlags featureFlags )
253- : base ( filters , featureFlags )
225+ Map filters )
226+ : base ( filters )
254227 {
255228 _consumerBuilder = consumerBuilder ;
256229 }
@@ -267,15 +240,28 @@ public override IConsumerBuilder Builder()
267240 /// </summary>
268241 public class StreamFilterOptions : IConsumerBuilder . IStreamFilterOptions
269242 {
270- private IConsumerBuilder . IStreamOptions _streamOptions ;
271- private Map _filters ;
243+ private readonly IConsumerBuilder . IStreamOptions _streamOptions ;
244+ private readonly Map _filters ;
272245
273246 public StreamFilterOptions ( IConsumerBuilder . IStreamOptions streamOptions , Map filters )
274247 {
275248 _streamOptions = streamOptions ;
276249 _filters = filters ;
277250 }
278251
252+ public IConsumerBuilder . IStreamFilterOptions Sql ( string sql )
253+ {
254+ if ( string . IsNullOrWhiteSpace ( sql ) )
255+ {
256+ throw new ArgumentNullException ( nameof ( sql ) ) ;
257+ }
258+
259+
260+ _filters [ Consts . SqlFilter ] =
261+ new DescribedValue ( Consts . s_streamSqlFilterSymbol , sql ) ;
262+ return this ;
263+ }
264+
279265 public IConsumerBuilder . IStreamOptions Stream ( )
280266 {
281267 return _streamOptions ;
@@ -328,9 +314,9 @@ public IConsumerBuilder.IStreamFilterOptions PropertySymbol(string key, string v
328314
329315 private StreamFilterOptions PropertyFilter ( string propertyKey , object propertyValue )
330316 {
331- const string AmqpPropertiesFilter = "amqp:properties-filter" ;
332317
333- DescribedValue propertiesFilterValue = Filter ( AmqpPropertiesFilter ) ;
318+
319+ DescribedValue propertiesFilterValue = Filter ( Consts . AmqpPropertiesFilter ) ;
334320 Map propertiesFilter = ( Map ) propertiesFilterValue . Value ;
335321 // Note: you MUST use a symbol as the key
336322 propertiesFilter . Add ( new Symbol ( propertyKey ) , propertyValue ) ;
@@ -339,9 +325,8 @@ private StreamFilterOptions PropertyFilter(string propertyKey, object propertyVa
339325
340326 private StreamFilterOptions ApplicationPropertyFilter ( string propertyKey , object propertyValue )
341327 {
342- const string AmqpApplicationPropertiesFilter = "amqp:application-properties-filter" ;
343-
344- DescribedValue applicationPropertiesFilterValue = Filter ( AmqpApplicationPropertiesFilter ) ;
328+
329+ DescribedValue applicationPropertiesFilterValue = Filter ( Consts . AmqpApplicationPropertiesFilter ) ;
345330 Map applicationPropertiesFilter = ( Map ) applicationPropertiesFilterValue . Value ;
346331 // Note: do NOT put a symbol as the key
347332 applicationPropertiesFilter . Add ( propertyKey , propertyValue ) ;
0 commit comments