Broker Event Listener
When the Event Exchange Plugin is enabled, if you add a bean of type BrokerEventListener
to the application context, it publishes selected broker events as BrokerEvent
instances, which can be consumed with a normal Spring ApplicationListener
or @EventListener
method.
Events are published by the broker to a topic exchange amq.rabbitmq.event
with a different routing key for each event type.
The listener uses event keys, which are used to bind an AnonymousQueue
to the exchange so the listener receives only selected events.
Since it is a topic exchange, wildcards can be used (as well as explicitly requesting specific events), as the following example shows:
@Bean
public BrokerEventListener eventListener() {
return new BrokerEventListener(connectionFactory(), "user.deleted", "channel.#", "queue.#");
}
You can further narrow the received events in individual event listeners, by using normal Spring techniques, as the following example shows:
@EventListener(condition = "event.eventType == 'queue.created'")
public void listener(BrokerEvent event) {
...
}