Class BrokerEventListener
- java.lang.Object
-
- org.springframework.amqp.rabbit.core.BrokerEventListener
-
- All Implemented Interfaces:
MessageListener
,ConnectionListener
,Aware
,ApplicationEventPublisherAware
,Lifecycle
,Phased
,SmartLifecycle
public class BrokerEventListener extends Object implements MessageListener, ApplicationEventPublisherAware, ConnectionListener, 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 asBrokerEvent
s. Such events can then be consumed using anApplicationListener
or@EventListener
method. AnAnonymousQueue
will be bound to theamq.rabbitmq.event
topic exchange with the supplied keys.- Since:
- 2.1
- Author:
- Gary Russell
-
-
Field Summary
-
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
-
Constructor Summary
Constructors Constructor Description BrokerEventListener(ConnectionFactory connectionFactory, String... eventKeys)
Construct an instance using the supplied connection factory and event keys.BrokerEventListener(AbstractMessageListenerContainer container, 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 Exception
getBindingsFailedException()
Return any exception thrown when attempting to bind the queue to the event exchange.int
getPhase()
boolean
isAutoStartup()
boolean
isRunning()
void
onCreate(Connection connection)
Called when a new connection is established.void
onMessage(Message message)
Delivers a single message.void
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
void
setAutoStartup(boolean autoStartup)
void
setPhase(int phase)
void
start()
void
stop()
-
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
-
Methods inherited from interface org.springframework.amqp.core.MessageListener
containerAckMode, isAsyncReplies, onMessageBatch
-
Methods inherited from interface org.springframework.context.SmartLifecycle
stop
-
-
-
-
Constructor Detail
-
BrokerEventListener
public BrokerEventListener(ConnectionFactory connectionFactory, 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.event
topic exchange. They can therefore match wildcards; examples areuser.#, queue.created
. Refer to the plugin documentation for information about available events. A single-threadedDirectMessageListenerContainer
will be created; its lifecycle will be controlled by this object'sSmartLifecycle
methods.- Parameters:
connectionFactory
- the connection factory.eventKeys
- the event keys.
-
BrokerEventListener
public BrokerEventListener(AbstractMessageListenerContainer container, 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.event
topic 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'sSmartLifecycle
methods. 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(ApplicationEventPublisher applicationEventPublisher)
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
getBindingsFailedException
@Nullable public Exception getBindingsFailedException()
Return any exception thrown when attempting to bind the queue to the event exchange.- Returns:
- the exception.
-
getPhase
public int getPhase()
- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in interfaceSmartLifecycle
-
setPhase
public void setPhase(int phase)
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartup
in interfaceSmartLifecycle
-
setAutoStartup
public void setAutoStartup(boolean autoStartup)
-
onMessage
public void onMessage(Message message)
Description copied from interface:MessageListener
Delivers a single message.- Specified by:
onMessage
in interfaceMessageListener
- Parameters:
message
- the message.
-
onCreate
public void onCreate(@Nullable Connection connection)
Description copied from interface:ConnectionListener
Called when a new connection is established.- Specified by:
onCreate
in interfaceConnectionListener
- Parameters:
connection
- the connection.
-
-