@@ -2658,22 +2658,56 @@ end}.
26582658{mapping , " message_interceptors.incoming.$interceptor.overwrite" , " rabbit.incoming_message_interceptors" , [
26592659 {datatype , {enum , [true , false ]}}]}.
26602660
2661+ % Pseudo-key to include the interceptor in the list of interceptors.
2662+ % - If any other configuration is provided for the interceptor this
2663+ % configuration is not required.
2664+ % - If no other configuration is provided, this one is required so that the
2665+ % interceptor gets invoked.
2666+ {mapping , " message_interceptors.incoming.$interceptor.enabled" , " rabbit.incoming_message_interceptors" , [
2667+ {datatype , {enum , [true ]}}]}.
2668+
2669+ {mapping , " message_interceptors.incoming.set_header_timestamp.overwrite" , " rabbit.incoming_message_interceptors" , [
2670+ {datatype , {enum , [true , false ]}}]}.
2671+
2672+ {mapping , " message_interceptors.incoming.set_header_routing_node.overwrite" , " rabbit.incoming_message_interceptors" , [
2673+ {datatype , {enum , [true , false ]}}]}.
2674+
26612675{translation , " rabbit.incoming_message_interceptors" ,
26622676 fun (Conf ) ->
2663- case cuttlefish_variable :filter_by_prefix (" message_interceptors" , Conf ) of
2677+ case cuttlefish_variable :filter_by_prefix (" message_interceptors.incoming " , Conf ) of
26642678 [] ->
26652679 cuttlefish :unset ();
26662680 L ->
2667- [begin
2668- Interceptor = list_to_atom (Interceptor0 ),
2669- case lists :member (Interceptor , [set_header_timestamp ,
2670- set_header_routing_node ]) of
2671- true ->
2672- {Interceptor , Overwrite };
2673- false ->
2674- cuttlefish :invalid (io_lib :format (" ~p is invalid" , [Interceptor ]))
2675- end
2676- end || {[" message_interceptors" , " incoming" , Interceptor0 , " overwrite" ], Overwrite } <- L ]
2681+ InterceptorsConfig = [
2682+ {Module0 , Config , Value }
2683+ || {[" message_interceptors" , " incoming" , Module0 , Config ], Value } <- L
2684+ ],
2685+ {Result , Order0 } = lists :foldl (
2686+ fun ({Interceptor0 , Key0 , Value }, {Acc , Order }) ->
2687+ Interceptor = list_to_atom (Interceptor0 ),
2688+ Key = list_to_atom (Key0 ),
2689+ MapPutFun = fun (Key , Value ) -> fun (Old ) -> maps :put (Key , Value , Old ) end end ,
2690+ Module = case Interceptor of
2691+ set_header_timestamp ->
2692+ rabbit_header_timestamp_interceptor ;
2693+ set_header_routing_node ->
2694+ rabbit_header_routing_node_interceptor ;
2695+ _ ->
2696+ Interceptor
2697+ end ,
2698+ NewAcc =
2699+ maps :update_with (
2700+ Module ,
2701+ MapPutFun (Key , Value ),
2702+ #{Key => Value },
2703+ Acc ),
2704+ {NewAcc , [Module | Order ]}
2705+ end ,
2706+ {#{}, []},
2707+ InterceptorsConfig
2708+ ),
2709+ Order = lists :uniq (Order0 ),
2710+ [{O , maps :without ([enabled ], maps :get (O , Result ))} || O <- Order ]
26772711 end
26782712 end
26792713}.
0 commit comments