@@ -577,10 +577,9 @@ roundtrip_with_drain(Config, QueueType, QName)
577
577
% create a receiver link
578
578
TerminusDurability = none ,
579
579
Filter = consume_from_first (QueueType ),
580
- Properties = #{},
581
580
{ok , Receiver } = amqp10_client :attach_receiver_link (
582
581
Session , <<" test-receiver" >>, Address , unsettled ,
583
- TerminusDurability , Filter , Properties ),
582
+ TerminusDurability , Filter ),
584
583
585
584
% grant credit and drain
586
585
ok = amqp10_client :flow_link_credit (Receiver , 1 , never , true ),
@@ -2433,36 +2432,28 @@ queue_and_client_different_nodes(QueueLeaderNode, ClientNode, QueueType, Config)
2433
2432
2434
2433
2435
2434
stream_filtering (Config ) ->
2436
- Host = ? config (rmq_hostname , Config ),
2437
- Port = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_amqp ),
2438
- Stream = list_to_binary (atom_to_list (? FUNCTION_NAME ) ++ " -" ++ integer_to_list (rand :uniform (10000 ))),
2435
+ Stream = atom_to_binary (? FUNCTION_NAME ),
2439
2436
Address = <<" /amq/queue/" , Stream /binary >>,
2440
- Ch = rabbit_ct_client_helpers :open_channel (Config , 0 ),
2441
- Args = [{<<" x-queue-type" >>, longstr , <<" stream" >>}],
2442
- amqp_channel :call (Ch , # 'queue.declare' {queue = Stream ,
2443
- durable = true ,
2444
- arguments = Args }),
2445
-
2446
- % % we are going to publish several waves of messages with and without filter values.
2447
- % % we will then create subscriptions with various filter options
2448
- % % and make sure we receive only what we asked for and not all the messages.
2449
-
2450
- WaveCount = 1000 ,
2451
- OpnConf = #{address => Host ,
2452
- port => Port ,
2453
- transfer_limit_margin => 10 * WaveCount ,
2454
- container_id => atom_to_binary (? FUNCTION_NAME , utf8 ),
2455
- sasl => {plain , <<" guest" >>, <<" guest" >>}},
2437
+ Ch = rabbit_ct_client_helpers :open_channel (Config ),
2438
+ amqp_channel :call (Ch , # 'queue.declare' {
2439
+ queue = Stream ,
2440
+ durable = true ,
2441
+ arguments = [{<<" x-queue-type" >>, longstr , <<" stream" >>}]}),
2442
+ ok = rabbit_ct_client_helpers :close_channel (Ch ),
2456
2443
2444
+ OpnConf = connection_config (Config ),
2457
2445
{ok , Connection } = amqp10_client :open_connection (OpnConf ),
2458
2446
{ok , Session } = amqp10_client :begin_session (Connection ),
2459
2447
SenderLinkName = <<" test-sender" >>,
2460
2448
{ok , Sender } = amqp10_client :attach_sender_link (Session ,
2461
2449
SenderLinkName ,
2462
2450
Address ),
2463
-
2464
2451
wait_for_credit (Sender ),
2465
2452
2453
+ % % We are going to publish several waves of messages with and without filter values.
2454
+ % % We will then create subscriptions with various filter options
2455
+ % % and make sure we receive only what we asked for and not all the messages.
2456
+ WaveCount = 1000 ,
2466
2457
% % logic to publish a wave of messages with or without a filter value
2467
2458
Publish = fun (FilterValue ) ->
2468
2459
lists :foreach (fun (Seq ) ->
@@ -2475,7 +2466,7 @@ stream_filtering(Config) ->
2475
2466
#{<<" x-stream-filter-value" >> => FilterValue }}
2476
2467
end ,
2477
2468
FilterBin = rabbit_data_coercion :to_binary (FilterValue ),
2478
- SeqBin = rabbit_data_coercion : to_binary (Seq ),
2469
+ SeqBin = integer_to_binary (Seq ),
2479
2470
DTag = <<FilterBin /binary , SeqBin /binary >>,
2480
2471
Msg0 = amqp10_msg :new (DTag , <<" my-body" >>, false ),
2481
2472
Msg1 = amqp10_msg :set_application_properties (AppProps , Msg0 ),
@@ -2485,103 +2476,96 @@ stream_filtering(Config) ->
2485
2476
end , lists :seq (1 , WaveCount ))
2486
2477
end ,
2487
2478
2488
- % % publishing messages with the "apple" filter value
2489
- Publish (" apple" ),
2490
- % % publishing messages with no filter value
2479
+ % % Publish messages with the "apple" filter value.
2480
+ Publish (<< " apple" >> ),
2481
+ % % Publish messages with no filter value.
2491
2482
Publish (undefined ),
2492
- % % publishing messages with the "orange" filter value
2493
- Publish (" orange" ),
2483
+ % % Publish messages with the "orange" filter value.
2484
+ Publish (<< " orange" >> ),
2494
2485
ok = amqp10_client :detach_link (Sender ),
2495
2486
2496
2487
% filtering on "apple"
2497
2488
TerminusDurability = none ,
2498
- Properties = #{},
2499
- { ok , AppleReceiver } =
2500
- amqp10_client : attach_receiver_link ( Session , <<" test-receiver" >>,
2501
- Address , settled ,
2502
- TerminusDurability ,
2503
- #{<< " rabbitmq:stream-offset-spec " >> => << " first " >> ,
2504
- <<" rabbitmq:stream-filter " >> => <<" apple " >>} ,
2505
- Properties ),
2489
+ { ok , AppleReceiver } = amqp10_client : attach_receiver_link (
2490
+ Session ,
2491
+ <<" test-receiver-1 " >>,
2492
+ Address ,
2493
+ unsettled ,
2494
+ TerminusDurability ,
2495
+ #{ <<" rabbitmq:stream-offset-spec " >> => <<" first " >>,
2496
+ << " rabbitmq:stream-filter " >> => << " apple " >>} ),
2506
2497
ok = amqp10_client :flow_link_credit (AppleReceiver , 100 , 10 ),
2507
-
2508
2498
AppleMessages = receive_all_messages (AppleReceiver , []),
2509
2499
% % we should get less than all the waves combined
2510
2500
? assert (length (AppleMessages ) < WaveCount * 3 ),
2511
2501
% % client-side filtering
2512
- AppleFilteredMessages =
2513
- lists : filter ( fun ( Msg ) ->
2514
- maps :get (<<" filter" >>, amqp10_msg : application_properties ( Msg ) ) =:= <<" apple" >>
2515
- end , AppleMessages ),
2516
- ? assert ( length (AppleFilteredMessages ) =:= WaveCount ),
2502
+ AppleFilteredMessages = lists : filter ( fun ( Msg ) ->
2503
+ AP = amqp10_msg : application_properties ( Msg ),
2504
+ maps :get (<<" filter" >>, AP ) =:= <<" apple" >>
2505
+ end , AppleMessages ),
2506
+ ? assertEqual ( WaveCount , length (AppleFilteredMessages )),
2517
2507
ok = amqp10_client :detach_link (AppleReceiver ),
2518
2508
2519
2509
% % filtering on "apple" and "orange"
2520
- TerminusDurability = none ,
2521
- Properties = #{},
2522
- {ok , AppleOrangeReceiver } =
2523
- amqp10_client :attach_receiver_link (Session , <<" test-receiver" >>,
2524
- Address , settled ,
2525
- TerminusDurability ,
2526
- #{<<" rabbitmq:stream-offset-spec" >> => <<" first" >>,
2527
- <<" rabbitmq:stream-filter" >> => [<<" apple" >>, <<" orange" >>]},
2528
- Properties ),
2510
+ {ok , AppleOrangeReceiver } = amqp10_client :attach_receiver_link (
2511
+ Session ,
2512
+ <<" test-receiver-2" >>,
2513
+ Address ,
2514
+ unsettled ,
2515
+ TerminusDurability ,
2516
+ #{<<" rabbitmq:stream-offset-spec" >> => <<" first" >>,
2517
+ <<" rabbitmq:stream-filter" >> => [<<" apple" >>, <<" orange" >>]}),
2529
2518
ok = amqp10_client :flow_link_credit (AppleOrangeReceiver , 100 , 10 ),
2530
-
2531
2519
AppleOrangeMessages = receive_all_messages (AppleOrangeReceiver , []),
2532
2520
% % we should get less than all the waves combined
2533
2521
? assert (length (AppleOrangeMessages ) < WaveCount * 3 ),
2534
2522
% % client-side filtering
2535
- AppleOrangeFilteredMessages =
2536
- lists :filter (fun (Msg ) ->
2537
- AP = amqp10_msg :application_properties (Msg ),
2538
- maps :get (<<" filter" >>, AP ) =:= <<" apple" >> orelse
2539
- maps :get (<<" filter" >>, AP ) =:= <<" orange" >>
2540
- end , AppleOrangeMessages ),
2541
- ? assert (length (AppleOrangeFilteredMessages ) =:= WaveCount * 2 ),
2523
+ AppleOrangeFilteredMessages = lists :filter (fun (Msg ) ->
2524
+ AP = amqp10_msg :application_properties (Msg ),
2525
+ Filter = maps :get (<<" filter" >>, AP ),
2526
+ Filter =:= <<" apple" >> orelse Filter =:= <<" orange" >>
2527
+ end , AppleOrangeMessages ),
2528
+ ? assertEqual (WaveCount * 2 , length (AppleOrangeFilteredMessages )),
2542
2529
ok = amqp10_client :detach_link (AppleOrangeReceiver ),
2543
2530
2544
2531
% % filtering on "apple" and messages without a filter value
2545
- {ok , AppleUnfilteredReceiver } =
2546
- amqp10_client :attach_receiver_link (Session , <<" test-receiver" >>,
2547
- Address , settled ,
2548
- TerminusDurability ,
2549
- #{<<" rabbitmq:stream-offset-spec" >> => <<" first" >>,
2550
- <<" rabbitmq:stream-filter" >> => <<" apple" >>,
2551
- <<" rabbitmq:stream-match-unfiltered" >> => {boolean , true }},
2552
- Properties ),
2532
+ {ok , AppleUnfilteredReceiver } = amqp10_client :attach_receiver_link (
2533
+ Session ,
2534
+ <<" test-receiver-3" >>,
2535
+ Address ,
2536
+ unsettled ,
2537
+ TerminusDurability ,
2538
+ #{<<" rabbitmq:stream-offset-spec" >> => <<" first" >>,
2539
+ <<" rabbitmq:stream-filter" >> => <<" apple" >>,
2540
+ <<" rabbitmq:stream-match-unfiltered" >> => {boolean , true }}),
2553
2541
ok = amqp10_client :flow_link_credit (AppleUnfilteredReceiver , 100 , 10 ),
2554
2542
2555
2543
AppleUnfilteredMessages = receive_all_messages (AppleUnfilteredReceiver , []),
2556
2544
% % we should get less than all the waves combined
2557
2545
? assert (length (AppleUnfilteredMessages ) < WaveCount * 3 ),
2558
2546
% % client-side filtering
2559
- AppleUnfilteredFilteredMessages =
2560
- lists :filter (fun (Msg ) ->
2561
- AP = amqp10_msg :application_properties (Msg ),
2562
- maps :is_key (<<" filter" >>, AP ) =:= false orelse
2563
- maps :get (<<" filter" >>, AP ) =:= <<" apple" >>
2564
- end , AppleUnfilteredMessages ),
2565
- ? assert (length (AppleUnfilteredFilteredMessages ) =:= WaveCount * 2 ),
2547
+ AppleUnfilteredFilteredMessages = lists :filter (fun (Msg ) ->
2548
+ AP = amqp10_msg :application_properties (Msg ),
2549
+ not maps :is_key (<<" filter" >>, AP ) orelse
2550
+ maps :get (<<" filter" >>, AP ) =:= <<" apple" >>
2551
+ end , AppleUnfilteredMessages ),
2552
+ ? assertEqual (WaveCount * 2 , length (AppleUnfilteredFilteredMessages )),
2566
2553
ok = amqp10_client :detach_link (AppleUnfilteredReceiver ),
2567
2554
2568
2555
delete_queue (Config , Stream ),
2569
- ok = amqp10_client :close_connection (Connection ),
2570
- ok .
2571
-
2572
- receive_all_messages (Receiver , Acc ) ->
2573
- receive
2574
- {amqp10_msg , Receiver , InMsg } ->
2575
- ok = amqp10_client :accept_msg (Receiver , InMsg ),
2576
- receive_all_messages (Receiver , [InMsg ] ++ Acc )
2577
- after 1000 ->
2578
- Acc
2579
- end .
2580
-
2556
+ ok = amqp10_client :close_connection (Connection ).
2581
2557
2582
2558
% % internal
2583
2559
% %
2584
2560
2561
+ receive_all_messages (Receiver , Acc ) ->
2562
+ receive {amqp10_msg , Receiver , Msg } ->
2563
+ ok = amqp10_client :accept_msg (Receiver , Msg ),
2564
+ receive_all_messages (Receiver , [Msg | Acc ])
2565
+ after 500 ->
2566
+ lists :reverse (Acc )
2567
+ end .
2568
+
2585
2569
connection_config (Config ) ->
2586
2570
connection_config (0 , Config ).
2587
2571
0 commit comments