Class BrokerEventListener
- java.lang.Object
-
- org.springframework.amqp.rabbit.core.BrokerEventListener
-
- All Implemented Interfaces:
org.springframework.amqp.core.MessageListener,ConnectionListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
public class BrokerEventListener extends java.lang.Object implements org.springframework.amqp.core.MessageListener, org.springframework.context.ApplicationEventPublisherAware, ConnectionListener, org.springframework.context.SmartLifecycle
When the event-exchange-plugin is enabled (see https://www.rabbitmq.com/event-exchange.html), if an object of this type is declared as a bean, selected events will be published asBrokerEvents. Such events can then be consumed using anApplicationListeneror@EventListenermethod. AnAnonymousQueuewill be bound to theamq.rabbitmq.eventtopic exchange with the supplied keys.- Since:
- 2.1
-
-
Constructor Summary
Constructors Constructor Description BrokerEventListener(ConnectionFactory connectionFactory, java.lang.String... eventKeys)Construct an instance using the supplied connection factory and event keys.BrokerEventListener(AbstractMessageListenerContainer container, java.lang.String... eventKeys)Construct an instance using the supplied listener container factory and event keys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ExceptiongetBindingsFailedException()Return any exception thrown when attempting to bind the queue to the event exchange.intgetPhase()booleanisAutoStartup()booleanisRunning()voidonCreate(Connection connection)Called when a new connection is established.voidonMessage(org.springframework.amqp.core.Message message)voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)voidsetAutoStartup(boolean autoStartup)voidsetPhase(int phase)voidstart()voidstop()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.amqp.rabbit.connection.ConnectionListener
onClose, onFailed, onShutDown
-
-
-
-
Constructor Detail
-
BrokerEventListener
public BrokerEventListener(ConnectionFactory connectionFactory, java.lang.String... eventKeys)
Construct an instance using the supplied connection factory and event keys. Event keys are patterns to match routing keys for events published to theamq.rabbitmq.eventtopic exchange. They can therefore match wildcards; examples areuser.#, queue.created. Refer to the plugin documentation for information about available events. A single-threadedDirectMessageListenerContainerwill be created; its lifecycle will be controlled by this object'sSmartLifecyclemethods.- Parameters:
connectionFactory- the connection factory.eventKeys- the event keys.
-
BrokerEventListener
public BrokerEventListener(AbstractMessageListenerContainer container, java.lang.String... eventKeys)
Construct an instance using the supplied listener container factory and event keys. Event keys are patterns to match routing keys for events published to theamq.rabbitmq.eventtopic exchange. They can therefore match wildcards; examples areuser.#, queue.created. Refer to the plugin documentation for information about available events. The container's lifecycle will be not be controlled by this object'sSmartLifecyclemethods. The container should not be configured with queues or aMessageListener; those properties will be replaced.- Parameters:
container- the listener container.eventKeys- the event keys.
-
-
Method Detail
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
- Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
getBindingsFailedException
@Nullable public java.lang.Exception getBindingsFailedException()
Return any exception thrown when attempting to bind the queue to the event exchange.- Returns:
- the exception.
-
start
public void start()
- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()
- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()
- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
setPhase
public void setPhase(int phase)
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
setAutoStartup
public void setAutoStartup(boolean autoStartup)
-
onMessage
public void onMessage(org.springframework.amqp.core.Message message)
- Specified by:
onMessagein interfaceorg.springframework.amqp.core.MessageListener
-
onCreate
public void onCreate(@Nullable Connection connection)Description copied from interface:ConnectionListenerCalled when a new connection is established.- Specified by:
onCreatein interfaceConnectionListener- Parameters:
connection- the connection.
-
-