@@ -322,13 +322,15 @@ stream_filtering(Config) ->
322
322
Version = ? config (version , Config ),
323
323
Client = ? config (stomp_client , Config ),
324
324
Stream = atom_to_list (? FUNCTION_NAME ) ++ " -" ++ integer_to_list (rand :uniform (10000 )),
325
+ % % subscription just to create the stream from STOMP
325
326
SubDestination = " /topic/stream-queue-test" ,
326
327
rabbit_stomp_client :send (
327
328
Client , " SUBSCRIBE" ,
328
329
[{" destination" , SubDestination },
329
330
{" receipt" , " foo" },
330
331
{" x-queue-name" , Stream },
331
332
{" x-queue-type" , " stream" },
333
+ {? HEADER_X_STREAM_FILTER_SIZE_BYTES , " 32" },
332
334
{" durable" , " true" },
333
335
{" auto-delete" , " false" },
334
336
{" id" , " 1234" },
@@ -341,7 +343,12 @@ stream_filtering(Config) ->
341
343
{" receipt" , " bar" }]),
342
344
{ok , Client2 , _ , _ } = stomp_receive (Client1 , " RECEIPT" ),
343
345
346
+ % % we are going to publish several waves of messages with and without filter values.
347
+ % % we will then create subscriptions with various filter options
348
+ % % and make sure we receive only what we asked for and not all the messages.
349
+
344
350
StreamDestination = " /amq/queue/" ++ Stream ,
351
+ % % logic to publish a wave of messages with or without a filter value
345
352
WaveCount = 1000 ,
346
353
Publish =
347
354
fun (C , FilterValue ) ->
@@ -360,11 +367,14 @@ stream_filtering(Config) ->
360
367
C1
361
368
end , C , lists :seq (1 , WaveCount ))
362
369
end ,
370
+ % % publishing messages with the "apple" filter value
363
371
Client3 = Publish (Client2 , " apple" ),
372
+ % % publishing messages with no filter value
364
373
Client4 = Publish (Client3 , undefined ),
374
+ % % publishing messages with the "orange" filter value
365
375
Client5 = Publish (Client4 , " orange" ),
366
376
367
- % % one filter
377
+ % % filtering on "apple"
368
378
rabbit_stomp_client :send (
369
379
Client5 , " SUBSCRIBE" ,
370
380
[{" destination" , StreamDestination },
@@ -374,19 +384,22 @@ stream_filtering(Config) ->
374
384
{" x-stream-filter" , " apple" },
375
385
{" x-stream-offset" , " first" }]),
376
386
{Client6 , AppleMessages } = stomp_receive_messages (Client5 , Version ),
387
+ % % we should get less than all the waves combined
377
388
? assert (length (AppleMessages ) < WaveCount * 3 ),
389
+ % % client-side filtering
378
390
AppleFilteredMessages =
379
391
lists :filter (fun (H ) ->
380
392
proplists :get_value (" x-stream-filter-value" , H ) =:= " apple"
381
393
end , AppleMessages ),
394
+ % % we should have only the "apple" messages
382
395
? assert (length (AppleFilteredMessages ) =:= WaveCount ),
383
396
rabbit_stomp_client :send (
384
397
Client6 , " UNSUBSCRIBE" , [{" destination" , StreamDestination },
385
398
{" id" , " 0" },
386
399
{" receipt" , " bar" }]),
387
400
{ok , Client7 , _ , _ } = stomp_receive (Client6 , " RECEIPT" ),
388
401
389
- % % two filters
402
+ % % filtering on "apple" and "orange"
390
403
rabbit_stomp_client :send (
391
404
Client7 , " SUBSCRIBE" ,
392
405
[{" destination" , StreamDestination },
@@ -396,20 +409,23 @@ stream_filtering(Config) ->
396
409
{" x-stream-filter" , " apple,orange" },
397
410
{" x-stream-offset" , " first" }]),
398
411
{Client8 , AppleOrangeMessages } = stomp_receive_messages (Client7 , Version ),
412
+ % % we should get less than all the waves combined
399
413
? assert (length (AppleOrangeMessages ) < WaveCount * 3 ),
414
+ % % client-side filtering
400
415
AppleOrangeFilteredMessages =
401
416
lists :filter (fun (H ) ->
402
417
proplists :get_value (" x-stream-filter-value" , H ) =:= " apple" orelse
403
418
proplists :get_value (" x-stream-filter-value" , H ) =:= " orange"
404
419
end , AppleOrangeMessages ),
420
+ % % we should have only the "apple" and "orange" messages
405
421
? assert (length (AppleOrangeFilteredMessages ) =:= WaveCount * 2 ),
406
422
rabbit_stomp_client :send (
407
423
Client8 , " UNSUBSCRIBE" , [{" destination" , StreamDestination },
408
424
{" id" , " 0" },
409
425
{" receipt" , " bar" }]),
410
426
{ok , Client9 , _ , _ } = stomp_receive (Client8 , " RECEIPT" ),
411
427
412
- % % one filter and unfiltered
428
+ % % filtering on "apple" and messages without a filter value
413
429
rabbit_stomp_client :send (
414
430
Client9 , " SUBSCRIBE" ,
415
431
[{" destination" , StreamDestination },
@@ -420,12 +436,15 @@ stream_filtering(Config) ->
420
436
{" x-stream-match-unfiltered" , " true" },
421
437
{" x-stream-offset" , " first" }]),
422
438
{Client10 , AppleUnfilteredMessages } = stomp_receive_messages (Client9 , Version ),
439
+ % % we should get less than all the waves combined
423
440
? assert (length (AppleUnfilteredMessages ) < WaveCount * 3 ),
441
+ % % client-side filtering
424
442
AppleUnfilteredFilteredMessages =
425
443
lists :filter (fun (H ) ->
426
444
proplists :get_value (" x-stream-filter-value" , H ) =:= " apple" orelse
427
445
proplists :get_value (" x-stream-filter-value" , H ) =:= undefined
428
446
end , AppleUnfilteredMessages ),
447
+ % % we should have only the "apple" messages and messages without a filter value
429
448
? assert (length (AppleUnfilteredFilteredMessages ) =:= WaveCount * 2 ),
430
449
rabbit_stomp_client :send (
431
450
Client10 , " UNSUBSCRIBE" , [{" destination" , StreamDestination },
0 commit comments