Skip to content

Commit 521d071

Browse files
Policies guide: first updates for rabbitmqadmin 2.2.0
1 parent aacaacb commit 521d071

File tree

1 file changed

+154
-7
lines changed

1 file changed

+154
-7
lines changed

versioned_docs/version-4.1/policies.md

Lines changed: 154 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ that cannot be changed at runtime. Two key examples are:
136136
Those values intentionally cannot be configured by policies: their values are fixed at queue declaration time.
137137

138138

139-
## How to Define a Policy
139+
## How to Define a Policy {#defining}
140140

141141
An example of defining a policy looks like:
142142

143143
<Tabs groupId="examples">
144-
<TabItem value="bash" label="bash" default>
144+
<TabItem value="bash" label="rabbitmqctl with bash" default>
145145
```bash
146146
rabbitmqctl set_policy federate-me \
147147
"^federated\." '{"federation-upstream-set":"all"}' \
@@ -150,7 +150,18 @@ rabbitmqctl set_policy federate-me \
150150
```
151151
</TabItem>
152152

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">
154165
```PowerShell
155166
rabbitmqctl.bat set_policy federate-me ^
156167
"^federated\." "{""federation-upstream-set"":""all""}" ^
@@ -159,6 +170,17 @@ rabbitmqctl.bat set_policy federate-me ^
159170
```
160171
</TabItem>
161172

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+
162184
<TabItem value="HTTP API" label="HTTP API">
163185
```ini
164186
PUT /api/policies/%2f/federate-me
@@ -261,6 +283,12 @@ be federated and has message TTL. At most one policy will apply to a
261283
resource at any given time, but we can apply multiple
262284
definitions in that policy.
263285

286+
:::tip
287+
288+
See [Updating Policies](#updating) below as well.
289+
290+
:::
291+
264292
A federation policy definition would require an <em>upstream set</em>
265293
to be specified, so we would need the `federation-upstream-set`
266294
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.
271299
Here's an example:
272300

273301
<Tabs groupId="examples">
274-
<TabItem value="bash" label="bash" default>
302+
<TabItem value="bash" label="rabbitmqctl with bash" default>
275303
```bash
276304
rabbitmqctl set_policy ttl-fed \
277305
"^tf\." '{"federation-upstream-set":"all", "message-ttl":60000}' \
@@ -280,7 +308,18 @@ rabbitmqctl set_policy ttl-fed \
280308
```
281309
</TabItem>
282310

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">
284323
```PowerShell
285324
rabbitmqctl set_policy ttl-fed ^
286325
"^tf\." "{""federation-upstream-set"":""all"", ""message-ttl"":60000}" ^
@@ -289,6 +328,17 @@ rabbitmqctl set_policy ttl-fed ^
289328
```
290329
</TabItem>
291330

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+
292342
<TabItem value="HTTP API" label="HTTP API">
293343
```ini
294344
PUT /api/policies/%2f/ttl-fed
@@ -540,7 +590,7 @@ instead of `set_policy`. In the HTTP API, `/api/policies/` in request path
540590
becomes `/api/operator-policies/`:
541591

542592
<Tabs groupId="examples">
543-
<TabItem value="bash" label="bash" default>
593+
<TabItem value="bash" label="rabbitmqctl with bash" default>
544594
```bash
545595
rabbitmqctl set_operator_policy transient-queue-ttl \
546596
"^amq\." '{"expires":1800000}' \
@@ -549,7 +599,17 @@ rabbitmqctl set_operator_policy transient-queue-ttl \
549599
```
550600
</TabItem>
551601

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">
553613
```PowerShell
554614
rabbitmqctl.bat set_operator_policy transient-queue-ttl ^
555615
"^amq\." "{""expires"": 1800000}" ^
@@ -558,6 +618,16 @@ rabbitmqctl.bat set_operator_policy transient-queue-ttl ^
558618
```
559619
</TabItem>
560620

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+
561631
<TabItem value="HTTP API" label="HTTP API">
562632
```ini
563633
PUT /api/operator-policies/%2f/transient-queue-ttl
@@ -606,6 +676,83 @@ HTTP API and Web UI.
606676
management.restrictions.operator_policy_changes.disabled = true
607677
```
608678

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+
609756
## Troubleshooting
610757

611758
### Multiple Policies Have Conflicting Priorities

0 commit comments

Comments
 (0)