@@ -136,12 +136,12 @@ that cannot be changed at runtime. Two key examples are:
136
136
Those values intentionally cannot be configured by policies: their values are fixed at queue declaration time.
137
137
138
138
139
- ## How to Define a Policy
139
+ ## How to Define a Policy {#defining}
140
140
141
141
An example of defining a policy looks like:
142
142
143
143
<Tabs groupId =" examples " >
144
- <TabItem value =" bash " label =" bash " default >
144
+ <TabItem value =" bash " label =" rabbitmqctl with bash" default >
145
145
``` bash
146
146
rabbitmqctl set_policy federate-me \
147
147
" ^federated\." ' {"federation-upstream-set":"all"}' \
@@ -150,7 +150,18 @@ rabbitmqctl set_policy federate-me \
150
150
```
151
151
</TabItem >
152
152
153
- <TabItem value =" PowerShell " label =" PowerShell " >
153
+ <TabItem value =" rabbitmqadmin-bash " label =" rabbitmqadmin with bash " >
154
+ ``` bash
155
+ rabbitmqadmin policies declare \
156
+ --name " federate-me" \
157
+ --pattern " ^federated\." \
158
+ --definition ' {"federation-upstream-set":"all"}' \
159
+ --priority 1 \
160
+ --apply-to " exchanges"
161
+ ```
162
+ </TabItem >
163
+
164
+ <TabItem value =" PowerShell " label =" rabbitmqctl with PowerShell " >
154
165
``` PowerShell
155
166
rabbitmqctl.bat set_policy federate-me ^
156
167
"^federated\." "{""federation-upstream-set"":""all""}" ^
@@ -159,6 +170,17 @@ rabbitmqctl.bat set_policy federate-me ^
159
170
```
160
171
</TabItem >
161
172
173
+ <TabItem value =" rabbitmqadmin-PowerShell " label =" rabbitmqadmin with PowerShell " >
174
+ ``` PowerShell
175
+ rabbitmqadmin policies declare ^
176
+ --name "federate-me" ^
177
+ --pattern "^federated\." ^
178
+ --definition "{""federation-upstream-set"":""all""}" ^
179
+ --priority 1 ^
180
+ --apply-to "exchanges"
181
+ ```
182
+ </TabItem >
183
+
162
184
<TabItem value =" HTTP API " label =" HTTP API " >
163
185
``` ini
164
186
PUT /api/policies/%2f/federate-me
@@ -261,6 +283,12 @@ be federated and has message TTL. At most one policy will apply to a
261
283
resource at any given time, but we can apply multiple
262
284
definitions in that policy.
263
285
286
+ ::: tip
287
+
288
+ See [ Updating Policies] ( #updating ) below as well.
289
+
290
+ :::
291
+
264
292
A federation policy definition would require an <em >upstream set</em >
265
293
to be specified, so we would need the ` federation-upstream-set `
266
294
key in our definition. On the other hand to define some queues as TTL-enabled,
@@ -271,7 +299,7 @@ keys combined in the same policy definition.
271
299
Here's an example:
272
300
273
301
<Tabs groupId =" examples " >
274
- <TabItem value =" bash " label =" bash " default >
302
+ <TabItem value =" bash " label =" rabbitmqctl with bash" default >
275
303
``` bash
276
304
rabbitmqctl set_policy ttl-fed \
277
305
" ^tf\." ' {"federation-upstream-set":"all", "message-ttl":60000}' \
@@ -280,7 +308,18 @@ rabbitmqctl set_policy ttl-fed \
280
308
```
281
309
</TabItem >
282
310
283
- <TabItem value =" PowerShell " label =" PowerShell " >
311
+ <TabItem value =" rabbitmqadmin " label =" rabbitmqadmin with bash " >
312
+ ``` bash
313
+ rabbitmqadmin policies declare \
314
+ --name ' ttl-fed' \
315
+ --definition ' {"federation-upstream-set":"all", "message-ttl":60000}' \
316
+ --pattern ' ^tf\.' \
317
+ --priority 1 \
318
+ --apply-to ' queues'
319
+ ```
320
+ </TabItem >
321
+
322
+ <TabItem value =" PowerShell " label =" rabbitmqctl.bat with PowerShell " >
284
323
``` PowerShell
285
324
rabbitmqctl set_policy ttl-fed ^
286
325
"^tf\." "{""federation-upstream-set"":""all"", ""message-ttl"":60000}" ^
@@ -289,6 +328,17 @@ rabbitmqctl set_policy ttl-fed ^
289
328
```
290
329
</TabItem >
291
330
331
+ <TabItem value =" rabbitmqadmin-PowerShell " label =" rabbitmqadmin with PowerShell " >
332
+ ``` PowerShell
333
+ rabbitmqadmin policies declare ^
334
+ --name "ttl-fed" ^
335
+ --definition "{""federation-upstream-set"":""all"", ""message-ttl"":60000}" ^
336
+ --pattern "^tf\." ^
337
+ --priority 1 ^
338
+ --apply-to "queues"
339
+ ```
340
+ </TabItem >
341
+
292
342
<TabItem value =" HTTP API " label =" HTTP API " >
293
343
``` ini
294
344
PUT /api/policies/%2f/ttl-fed
@@ -540,7 +590,7 @@ instead of `set_policy`. In the HTTP API, `/api/policies/` in request path
540
590
becomes ` /api/operator-policies/ ` :
541
591
542
592
<Tabs groupId =" examples " >
543
- <TabItem value =" bash " label =" bash " default >
593
+ <TabItem value =" bash " label =" rabbitmqctl with bash" default >
544
594
``` bash
545
595
rabbitmqctl set_operator_policy transient-queue-ttl \
546
596
" ^amq\." ' {"expires":1800000}' \
@@ -549,7 +599,17 @@ rabbitmqctl set_operator_policy transient-queue-ttl \
549
599
```
550
600
</TabItem >
551
601
552
- <TabItem value =" PowerShell " label =" PowerShell " >
602
+ <TabItem value =" rabbitmqadmin " label =" rabbitmqadmin with bash " >
603
+ ``` bash
604
+ rabbitmqadmin operator_policies declare --name ' transient-queue-ttl' \
605
+ --apply-to ' queues' \
606
+ --definition ' {"expires":1800000}' \
607
+ --pattern ' ^amq\.' \
608
+ --priority 1
609
+ ```
610
+ </TabItem >
611
+
612
+ <TabItem value =" PowerShell " label =" rabbitmqctl.bat with PowerShell " >
553
613
``` PowerShell
554
614
rabbitmqctl.bat set_operator_policy transient-queue-ttl ^
555
615
"^amq\." "{""expires"": 1800000}" ^
@@ -558,6 +618,16 @@ rabbitmqctl.bat set_operator_policy transient-queue-ttl ^
558
618
```
559
619
</TabItem >
560
620
621
+ <TabItem value =" rabbitmqadmin-PowerShell " label =" rabbitmqadmin with PowerShell " >
622
+ ``` PowerShell
623
+ rabbitmqadmin operator_policies declare --name "transient-queue-ttl" ^
624
+ --apply-to "queues" ^
625
+ --definition "{""expires"": 1800000}" ^
626
+ --pattern "^amq\." ^
627
+ --priority 1
628
+ ```
629
+ </TabItem >
630
+
561
631
<TabItem value =" HTTP API " label =" HTTP API " >
562
632
``` ini
563
633
PUT /api/operator-policies/%2f/transient-queue-ttl
@@ -606,6 +676,83 @@ HTTP API and Web UI.
606
676
management.restrictions.operator_policy_changes.disabled = true
607
677
```
608
678
679
+ ## Updating Policies {#updating}
680
+
681
+ A policy can be updated by re-declaring it with a different definition, priority, and so on.
682
+ This requires the operator to have a full policy definition.
683
+
684
+ Alternatively, [ ` rabbitmqadmin ` v2] ( ./management-cli ) provides commands that can modify
685
+ policy definitions, declare override policies and blanket policies.
686
+
687
+ ### Policy Redefinition {#redefining}
688
+
689
+ If a full policy definition is known, [ redefining] ( #defining ) a policy with an updated definition
690
+ and (optionally) a new priority but the same original name will update it.
691
+
692
+ ::: important
693
+
694
+ The effects of new settings on queues, streams and exchanges will take a moment to become effective,
695
+ in particular for clusters with a large number of entites (say, thousands).
696
+
697
+ :::
698
+
699
+ ### Deleting Policy Definition Keys {#deleting-keys}
700
+
701
+ To delete one or multiple keys from a policy definition, use [ ` rabbitmqadmin policies delete_definition_keys ` ] ( ./management-cli ) :
702
+
703
+ <Tabs groupId =" examples " >
704
+ <TabItem value =" bash " label =" bash " default >
705
+ ``` bash
706
+ # removes all keys related to classic queue mirroring (that feature was removed in RabbitMQ 4.x)
707
+ # from the definition of a policy named "cq.policies.1" in virtual host vh-1
708
+ rabbitmqadmin --vhost " vh-1" policies delete_definition_keys --name " cq.policies.1" --definition-keys " ha-mode,ha-params,ha-promote-on-shutdown,ha-promote-on-failure,ha-sync-mode,ha-sync-batch-size"
709
+ ```
710
+ </TabItem >
711
+
712
+ <TabItem value =" PowerShell " label =" PowerShell " >
713
+ ``` PowerShell
714
+ # removes all keys related to classic queue mirroring (that feature was removed in RabbitMQ 4.x)
715
+ # from the definition of a policy named "cq.policies.1" in virtual host vh-1
716
+ rabbitmqadmin --vhost "vh-1" policies delete_definition_keys --name "cq.policies.1" --definition-keys "ha-mode,ha-params,ha-promote-on-shutdown,ha-promote-on-failure,ha-sync-mode,ha-sync-batch-size"
717
+ ```
718
+ </TabItem >
719
+ </Tabs >
720
+
721
+
722
+ The ` --definitions-keys ` parameter accepts a single definition key or a command-separated list of keys.
723
+
724
+ To perform the same operation across all policies in a virtual host, use [ ` rabbitmqadmin policies delete_definition_keys_from_all_in ` ] ( ./management-cli ) :
725
+
726
+ ``` bash
727
+ # removes all keys related to classic queue mirroring (that feature was removed in RabbitMQ 4.x)
728
+ # from all policy definitions in virtual host vh-1
729
+ rabbitmqadmin --vhost " vh-1" policies delete_definition_keys_from_all_in --definition-keys " ha-mode,ha-params,ha-promote-on-shutdown,ha-promote-on-failure,ha-sync-mode,ha-sync-batch-size"
730
+ ```
731
+
732
+
733
+ ### Partially Updating Policy Definition {#patching}
734
+
735
+ [ ` rabbitmqadmin policies patch ` ] ( ./management-cli ) is a command that can update a policy
736
+ using a partial definition, for example, to add a [ ` max-length ` key] ( ./maxlength/ ) to an existing
737
+ policy:
738
+
739
+ ``` bash
740
+ rabbitmqadmin policies patch --name " cq.pol.1" --definition ' {"max-length": 1000000}'
741
+ ```
742
+
743
+ The new ` --definition ` object will be merged into the existing policy definition.
744
+
745
+ In the following example, an existing policy named ` queues.pol.1 ` in the default virtual host (` / ` )
746
+ is updated to enable [ queue federation] ( ./federated-queues ) to all the configured upstreams for the matched queues,
747
+ without affecting the rest of the policy definitions:
748
+
749
+ ``` bash
750
+ rabbitmqadmin policies patch --name " queues.pol.1" --definition ' {"federation-upstream-set":"all"}'
751
+ ```
752
+
753
+
754
+
755
+
609
756
## Troubleshooting
610
757
611
758
### Multiple Policies Have Conflicting Priorities
0 commit comments