@@ -93,9 +93,14 @@ merge_operator_definitions(Policy, OpPolicy) ->
93
93
lists :umerge (Keys , OpKeys )).
94
94
95
95
set (Q0 ) when ? is_amqqueue (Q0 ) ->
96
- Name = amqqueue :get_name (Q0 ),
97
- Policy = match (Name ),
98
- OpPolicy = match_op (Name ),
96
+ % % On queue.declare the queue record doesn't exist yet, so the later lookup in
97
+ % % `rabbit_amqqueue:is_policy_applicable` fails. Thus, let's send the whole record
98
+ % % through the match functions. `match_all` still needs to support resources only,
99
+ % % as that is used by some plugins. Maybe `match` too, difficult to figure out
100
+ % % what is public API and what is not, so let's support both `amqqueue` and `resource`
101
+ % % records as arguments.
102
+ Policy = match (Q0 ),
103
+ OpPolicy = match_op (Q0 ),
99
104
Q1 = amqqueue :set_policy (Q0 , Policy ),
100
105
Q2 = amqqueue :set_operator_policy (Q1 , OpPolicy ),
101
106
Q2 ;
@@ -147,9 +152,15 @@ list_formatted_op(VHost, Ref, AggregatorPid) ->
147
152
rabbit_control_misc :emitting_map (AggregatorPid , Ref ,
148
153
fun (P ) -> P end , list_formatted_op (VHost )).
149
154
155
+ match (Q ) when ? is_amqqueue (Q ) ->
156
+ # resource {virtual_host = VHost } = amqqueue :get_name (Q ),
157
+ match (Q , list (VHost ));
150
158
match (Name = # resource {virtual_host = VHost }) ->
151
159
match (Name , list (VHost )).
152
160
161
+ match_op (Q ) when ? is_amqqueue (Q ) ->
162
+ # resource {virtual_host = VHost } = amqqueue :get_name (Q ),
163
+ match (Q , list_op (VHost ));
153
164
match_op (Name = # resource {virtual_host = VHost }) ->
154
165
match (Name , list_op (VHost )).
155
166
@@ -172,15 +183,21 @@ get(Name, EntityName = #resource{virtual_host = VHost}) ->
172
183
match (EntityName , list (VHost )),
173
184
match (EntityName , list_op (VHost ))).
174
185
175
- match (Name , Policies ) ->
176
- case match_all (Name , Policies ) of
186
+ match (NameOrQueue , Policies ) ->
187
+ case match_all (NameOrQueue , Policies ) of
177
188
[] -> undefined ;
178
189
[Policy | _ ] -> Policy
179
190
end .
180
191
181
- match_all (Name , Policies ) ->
182
- lists :sort (fun priority_comparator /2 , [P || P <- Policies , matches (Name , P )]).
192
+ match_all (NameOrQueue , Policies ) ->
193
+ lists :sort (fun priority_comparator /2 , [P || P <- Policies , matches (NameOrQueue , P )]).
183
194
195
+ matches (Q , Policy ) when ? is_amqqueue (Q ) ->
196
+ # resource {name = Name , kind = Kind , virtual_host = VHost } = amqqueue :get_name (Q ),
197
+ matches_type (Kind , pget ('apply-to' , Policy )) andalso
198
+ is_applicable (Q , pget (definition , Policy )) andalso
199
+ match =:= re :run (Name , pget (pattern , Policy ), [{capture , none }]) andalso
200
+ VHost =:= pget (vhost , Policy );
184
201
matches (# resource {name = Name , kind = Kind , virtual_host = VHost } = Resource , Policy ) ->
185
202
matches_type (Kind , pget ('apply-to' , Policy )) andalso
186
203
is_applicable (Resource , pget (definition , Policy )) andalso
@@ -527,6 +544,8 @@ matches_type(_, _) -> false.
527
544
528
545
priority_comparator (A , B ) -> pget (priority , A ) >= pget (priority , B ).
529
546
547
+ is_applicable (Q , Policy ) when ? is_amqqueue (Q ) ->
548
+ rabbit_amqqueue :is_policy_applicable (Q , rabbit_data_coercion :to_list (Policy ));
530
549
is_applicable (# resource {kind = queue } = Resource , Policy ) ->
531
550
rabbit_amqqueue :is_policy_applicable (Resource , rabbit_data_coercion :to_list (Policy ));
532
551
is_applicable (_ , _ ) ->
0 commit comments