Client connection, channels, queues, consumers, and other parts of the system naturally generate events. For example, when a connection is accepted, authenticated and access to the target virtual host is authorised, it will emit an event of type connection_created
. When a connection is closed or fails for any reason, a connection_closed
event is emitted.
Monitoring and auditing services can be interested in observing those events. RabbitMQ has a minimalistic mechanism for event notifications that can be exposed to RabbitMQ clients with a plugin.
rabbitmq-event-exchange is a plugin that consumes internal events and re-publishes them to a topic exchange, thus exposing the events to clients (applications).
To consume the events, an application needs to declare a queue, bind it to a special system exchange and consume messages.
It declares a topic exchange called amq.rabbitmq.event
in the default virtual host. All events are published to this exchange with routing keys like 'exchange.created', 'binding.deleted' etc, so you can subscribe to only the events you're interested in.
The exchange behaves similarly to amq.rabbitmq.log
: everything gets published there; if you don't trust a user with the information that gets published, don't allow them access.
The plugin requires no configuration, just activate it:
rabbitmq-plugins enable rabbitmq_event_exchange
Each event has various properties associated with it. These are translated into AMQP 0-9-1 data encoding and inserted in the message headers. The message body is always blank.
RabbitMQ and related plugins produce events with the following routing keys:
Queue, Exchange and Binding events:
queue.deleted
queue.created
exchange.created
exchange.deleted
binding.created
binding.deleted
Connection and Channel events:
connection.created
connection.closed
channel.created
channel.closed
Consumer events:
consumer.created
consumer.deleted
Policy and Parameter events:
policy.set
policy.cleared
parameter.set
parameter.cleared
Virtual host events:
vhost.created
vhost.deleted
User related events:
user.authentication.success
user.authentication.failure
user.created
user.deleted
user.password.changed
user.password.cleared
user.tags.set
Permission events:
permission.created
permission.deleted
Worker events:
shovel.worker.status
shovel.worker.removed
Link events:
federation.link.status
federation.link.removed
There is a usage example using the Java client in the rabbitmq-event-exchange repository.