rabbitmq / rabbitmq-server

Open source RabbitMQ: core server and tier 1 (built-in) plugins
https://www.rabbitmq.com/
Other
12.31k stars 3.92k forks source link

Support publishing AMQP 1.0 to Event Exchange #12714

Closed ansd closed 1 week ago

ansd commented 1 week ago

What?

Prior to this commit, the rabbitmq_event_exchange internally published always AMQP 0.9.1 messages to the amq.rabbitmq.event topic exchange. This commit allows users to configure the plugin to publish AMQP 1.0 messages instead.

Why?

Prior to this commit, when an AMQP 1.0 client consumed events, event properties that are lists were omitted. For example property client_properties of event connection.created or property arguments of event queue.created were omitted because of the following sequence:

  1. The event exchange plugins listens for all kind of internal events.
  2. The event exchange plugin re-publishes all events as AMQP 0.9.1 message to the event exchange.
  3. Later, when an AMQP 1.0 client consumes this message, the broker must translate the message from AMQP 0.9.1 to AMQP 1.0.
  4. This translation follows the rules outlined in https://www.rabbitmq.com/docs/conversions#amqpl-amqp
  5. Specifically, in this table the row before the last one describes the rule we're hitting here. It says that if the AMQP 0.9.1 header value is not an x- prefixed header and its value is an array or table, then this header is not converted. That's because AMQP 1.0 application-properties must be simple types as mandated in https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-application-properties

    How?

The user can configure the plugin as follows to have the plugin internally publish AMQP 1.0 messages:

event_exchange.protocol = amqp_1_0

To support complex types such as lists, the plugin sets all event properties as AMQP 1.0 message-annotations. The plugin prefixes all message annotation keys with x-opt- to comply with the AMQP 1.0 spec.

Alternative Design

An alternative design would have been to format all event properties e.g. as JSON within the message body. However, this breaks routing on specific event property values via a headers exchange.

Documentation

https://github.com/rabbitmq/rabbitmq-website/pull/2129