Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different AMQP address format for v1 and v2 #11604

Merged
merged 2 commits into from
Jul 3, 2024
Merged

Conversation

ansd
Copy link
Member

@ansd ansd commented Jul 2, 2024

This PR is a refinement of #10873.

Use different AMQP address format for v1 and v2 to distinguish between v1 and v2 address formats.

Previously, v1 and v2 address formats overlapped and behaved differently for example for:

/queue/:queue
/exchange/:exchange

This PR changes the v2 format to:

/e/:exchange/:routing-key
/e/:exchange
/q/:queue

to distinguish between v1 and v2 addresses.

This allows to call rabbit_deprecated_features:is_permitted(amqp_address_v1)
only if we know that the user requests address format v1.

Note that rabbit_deprecated_features:is_permitted/1 should only
be called when the old feature is actually used.

Use percent encoding / decoding for address URI format v2.
This allows to use any UTF-8 encoded characters including slashes (/)
in routing keys, exchange names, and queue names and is more future
safe.

Although less user friendly, the new address format is kept short to:

  1. reduce the per message network bandwidth
  2. reduce the per message disk overhead (note that the bare message including the to field must be stored unaltered)
  3. (reduce parsing overhead)

The alternative would have been something like:

/v2/exchange/:exchange/:routing-key
/v2/exchange/:exchange
/v2/queue/:queue

or to set some capabilities or properties when attaching a link denoting that address format v2 is used.
Neither of these alternatives is really more user friendly compared to the short version.

Docs PR updating https://www.rabbitmq.com/docs/next/amqp#address will follow soon.

to distinguish between v1 and v2 address formats.

Previously, v1 and v2 address formats overlapped and behaved differently
for example for:
```
/queue/:queue
/exchange/:exchange
```

This PR changes the v2 format to:
```
/e/:exchange/:routing-key
/e/:exchange
/q/:queue
```
to distinguish between v1 and v2 addresses.

This allows to call `rabbit_deprecated_features:is_permitted(amqp_address_v1)`
only if we know that the user requests address format v1.

Note that `rabbit_deprecated_features:is_permitted/1` should only
be called when the old feature is actually used.

Use percent encoding / decoding for address URI format v2.
This allows to use any UTF-8 encoded characters including slashes (`/`)
in routing keys, exchange names, and queue names and is more future
safe.
Partially copy file
https://github.com/ninenines/cowlib/blob/optimise-urldecode/src/cow_uri.erl
We use this copy because:
1. uri_string:unquote/1 is lax: It doesn't validate that characters that are
   required to be percent encoded are indeed percent encoded. In RabbitMQ,
   we want to enforce that proper percent encoding is done by AMQP clients.
2. uri_string:unquote/1 and cow_uri:urldecode/1 in cowlib v2.13.0 are both
   slow because they allocate a new binary for the common case where no
   character was percent encoded.
When a new cowlib version is released, we should make app rabbit depend on
app cowlib calling cow_uri:urldecode/1 and delete this file (rabbit_uri.erl).
@ansd ansd marked this pull request as ready for review July 3, 2024 16:37
@michaelklishin michaelklishin added this to the 4.0.0 milestone Jul 3, 2024
@michaelklishin michaelklishin merged commit 20aee3f into main Jul 3, 2024
251 checks passed
@michaelklishin michaelklishin deleted the amqp-addr branch July 3, 2024 23:32
acogoluegnes added a commit to rabbitmq/rabbitmq-amqp-java-client that referenced this pull request Jul 4, 2024
github-actions bot pushed a commit to rabbitmq/rabbitmq-amqp-java-client that referenced this pull request Jul 4, 2024
ansd added a commit that referenced this pull request Jul 4, 2024
This commit is a follow up of #11604

This commit changes the AMQP address format v2 from
```
/e/:exchange/:routing-key
/e/:exchange
/q/:queue
```
to
```
/exchanges/:exchange/:routing-key
/exchanges/:exchange
/queues/:queue
```

Advantages:
1. more user friendly
2. matches nicely with the plural forms of HTTP API v1 and HTTP API v2

This plural form is still non-overlapping with AMQP address format v1.

Although it might feel unusual at first to send a message to `/queues/q1`,
if you think about `queues` just being a namespace or entity type, this
address format makes sense.
ansd added a commit that referenced this pull request Jul 4, 2024
This commit is a follow up of #11604

This commit changes the AMQP address format v2 from
```
/e/:exchange/:routing-key
/e/:exchange
/q/:queue
```
to
```
/exchanges/:exchange/:routing-key
/exchanges/:exchange
/queues/:queue
```

Advantages:
1. more user friendly
2. matches nicely with the plural forms of HTTP API v1 and HTTP API v2

This plural form is still non-overlapping with AMQP address format v1.

Although it might feel unusual at first to send a message to `/queues/q1`,
if you think about `queues` just being a namespace or entity type, this
address format makes sense.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants