rabbitmqctl set_policy throws json parsing errors

488 views
Skip to first unread message

yenti...@outlook.com

unread,
Nov 9, 2022, 4:17:31 AM11/9/22
to rabbitmq-users
Hello,

We're trying to install RabbitMQ 3.11.2 on a Windows Server 2019 machine. The installation process goes well but when I try to configure policies (for example a dead letter exchange or message ttl) I run into the following error:

> rabbitmqctl set_policy --priority 0 --apply-to queues 'DLX' ".*" "{'dead-letter-exchange':'my-dlx'}"
Setting policy "DLX" for pattern ".*" to "{'dead-letter-exchange':'my-dlx'}" with priority "0" for vhost "/" ...
Error:
Could not parse JSON document: {error,
                                   {failed_to_decode_json,
                                       <<"{'dead-letter-exchange':'my-dlx'}">>}}

I executed the same command on RabbitMQ 3.10.10 and it works there. I've tried to modify the json but I can't get it to parse in 3.11.2. Did the syntax for set_policy or the json parser change in 3.11.x? If so can somebody explain how I should be setting policies in 3.11.x?

Kind regards,
Yenti

Michal Kuratczyk

unread,
Nov 9, 2022, 6:41:16 AM11/9/22
to rabbitm...@googlegroups.com
Hi,

In 3.11, we switched to a different JSON parsing library. There are two main differences compared to the old one:
1. it's much faster and uses less memory (which is why we switched)
2. it's more strict

What you are trying to specify is not a valid JSON - JSON doesn't allow single-quoted strings.
The old library apparently allowed that (and probably converted to double-quotes) but the new one, rightfully, just rejects that.

Best,

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/8f959154-3c69-4d22-b9a6-3f33f4068afan%40googlegroups.com.


--
Michał
RabbitMQ team

yenti...@outlook.com

unread,
Nov 16, 2022, 2:06:29 AM11/16/22
to rabbitmq-users
Hey Michał,

Thanks for the info, I've been trying to get this to work but everything I do throws this error:

Could not parse JSON document: {error,
                                   {failed_to_decode_json,
                                       <<"{dead-letter-exchange:my-dlx}">>}}

What I find interesting about this is that there are no quotes to be found around the key/value pair while the original error with single quotes did have those.

I've tried the following commands, first just swapping the quotes, then escaping the double quotes and finally the example that's available in the documentation for dlx but everything runs into that same error. I've also tried adding spaces between the key/value pair but that doesn't help either.


rabbitmqctl set_policy --priority 0 --apply-to queues 'DLX' '.*' '{"dead-letter-exchange":"my-dlx"}'
rabbitmqctl set_policy --priority 0 --apply-to queues "DLX" ".*" "{`"dead-letter-exchange`":`"my-dlx`"}"

rabbitmqctl set_policy --priority 0 --apply-to queues "DLX" ".*" "{""dead-letter-exchange"":""my-dlx""}"

Just to be 100% sure that I didn't make a mistake somewhere I tried to use the ConvertTo-Json function in PowerShell but that one also throws that same error.

$policy = @{"dead-letter-exchange"="my-dlx"}
$policyJson = $policy | ConvertTo-Json -Compress
rabbitmqctl set_policy --priority 0 --apply-to queues "DLX" ".*" "$policyJson"

Do you have any idea how to get this working in PowerShell?

Kind regards,
Yenti

Michal Kuratczyk

unread,
Nov 16, 2022, 2:31:54 AM11/16/22
to rabbitm...@googlegroups.com
Hi,

The first one is correct:
rabbitmqctl set_policy --priority 0 --apply-to queues 'DLX' '.*' '{"dead-letter-exchange":"my-dlx"}'

I copy-pasted this and it works for me.

Best,



--
Michał
RabbitMQ team

yenti...@outlook.com

unread,
Nov 16, 2022, 4:03:12 AM11/16/22
to rabbitmq-users
Hi,

Thats strange, it doesn't work when I try to execute it.
output.png
I also tried installing PowerShell 7 to see if that makes a difference but I'm getting the same error.
Not sure what I'm doing wrong here.

Kind regards,
Yenti

Michal Kuratczyk

unread,
Nov 16, 2022, 4:28:06 AM11/16/22
to rabbitm...@googlegroups.com
There is something wrong with how the quotes are passed. If you look at the first line of the error message ("Setting policy"), you'll see that quotes are no longer there.

When I do that, I see them fine:

$ rabbitmqctl set_policy --priority 0 --apply-to queues 'DLX' '.*' '{"dead-letter-exchange":"my-dlx"}'

Setting policy "DLX" for pattern ".*" to "{"dead-letter-exchange":"my-dlx"}" with priority "0" for vhost "/" ...

As a quick solution, I can suggest using a definitions import file to import this policy.

To check whether this is a Windows shell issue or RabbitMQ CLI on Windows issue, I'd need help from some Windows users.

Best,



--
Michał
RabbitMQ team
Reply all
Reply to author
Forward
0 new messages