@ManagedResource(description="Admin Tasks")
public class RabbitAdmin
extends java.lang.Object
implements org.springframework.amqp.core.AmqpAdmin, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_EXCHANGE_NAME
The default exchange name.
|
protected org.apache.commons.logging.Log |
logger
Logger available to subclasses.
|
static java.lang.Object |
QUEUE_CONSUMER_COUNT
Property key for the consumer count in the
Properties returned by
getQueueProperties(String). |
static java.lang.Object |
QUEUE_MESSAGE_COUNT
Property key for the message count in the
Properties returned by
getQueueProperties(String). |
static java.lang.Object |
QUEUE_NAME
Property key for the queue name in the
Properties returned by
getQueueProperties(String). |
| Constructor and Description |
|---|
RabbitAdmin(ConnectionFactory connectionFactory)
Construct an instance using the provided
ConnectionFactory. |
RabbitAdmin(RabbitTemplate rabbitTemplate)
Construct an instance using the provided
RabbitTemplate. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
If
autoStartup is set to true, registers a callback on the
ConnectionFactory to declare all exchanges and queues in the enclosing application context. |
void |
declareBinding(org.springframework.amqp.core.Binding binding) |
void |
declareExchange(org.springframework.amqp.core.Exchange exchange) |
org.springframework.amqp.core.Queue |
declareQueue()
Declares a server-named exclusive, autodelete, non-durable queue.
|
java.lang.String |
declareQueue(org.springframework.amqp.core.Queue queue)
Declare the given queue.
|
boolean |
deleteExchange(java.lang.String exchangeName) |
boolean |
deleteQueue(java.lang.String queueName) |
void |
deleteQueue(java.lang.String queueName,
boolean unused,
boolean empty) |
java.lang.String |
getBeanName() |
DeclarationExceptionEvent |
getLastDeclarationExceptionEvent() |
org.springframework.amqp.core.QueueInformation |
getQueueInfo(java.lang.String queueName) |
java.util.Properties |
getQueueProperties(java.lang.String queueName)
Returns 3 properties
QUEUE_NAME, QUEUE_MESSAGE_COUNT,
QUEUE_CONSUMER_COUNT, or null if the queue doesn't exist. |
RabbitTemplate |
getRabbitTemplate() |
void |
initialize()
Declares all the exchanges, queues and bindings in the enclosing application context, if any.
|
boolean |
isAutoStartup() |
boolean |
isRedeclareManualDeclarations()
Normally, when a connection is recovered, the admin only recovers auto-delete queues,
etc, that are declared as beans in the application context.
|
int |
purgeQueue(java.lang.String queueName) |
void |
purgeQueue(java.lang.String queueName,
boolean noWait) |
void |
removeBinding(org.springframework.amqp.core.Binding binding) |
void |
resetAllManualDeclarations()
Invoke this method to prevent the admin from recovering any declarations made
by calls to
declare*() methods. |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setAutoStartup(boolean autoStartup) |
void |
setBeanName(java.lang.String name) |
void |
setExplicitDeclarationsOnly(boolean explicitDeclarationsOnly)
Set to true to only declare
Declarable beans that are explicitly configured
to be declared by this admin. |
void |
setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions) |
void |
setRedeclareManualDeclarations(boolean redeclareManualDeclarations)
Normally, when a connection is recovered, the admin only recovers auto-delete
queues, etc, that are declared as beans in the application context.
|
void |
setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
Set a retry template for auto declarations.
|
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Set a task executor to use for async operations.
|
public static final java.lang.String DEFAULT_EXCHANGE_NAME
public static final java.lang.Object QUEUE_NAME
Properties returned by
getQueueProperties(String).public static final java.lang.Object QUEUE_MESSAGE_COUNT
Properties returned by
getQueueProperties(String).public static final java.lang.Object QUEUE_CONSUMER_COUNT
Properties returned by
getQueueProperties(String).protected final org.apache.commons.logging.Log logger
public RabbitAdmin(ConnectionFactory connectionFactory)
ConnectionFactory.connectionFactory - the connection factory - must not be null.public RabbitAdmin(RabbitTemplate rabbitTemplate)
RabbitTemplate. Use this
constructor when, for example, you want the admin operations to be performed within
the scope of the provided template's invoke() method.rabbitTemplate - the template - must not be null and must have a connection
factory.public void setAutoStartup(boolean autoStartup)
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext in interface org.springframework.context.ApplicationContextAwarepublic void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAwarepublic void setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions)
public DeclarationExceptionEvent getLastDeclarationExceptionEvent()
DeclarationExceptionEvent that was detected in this admin.public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
purgeQueue(String, boolean).taskExecutor - the executor to use.public RabbitTemplate getRabbitTemplate()
public void declareExchange(org.springframework.amqp.core.Exchange exchange)
declareExchange in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Delete an exchange from the broker") public boolean deleteExchange(java.lang.String exchangeName)
deleteExchange in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Declare a queue on the broker (this operation is not available remotely)") @Nullable public java.lang.String declareQueue(org.springframework.amqp.core.Queue queue)
declareQueue in interface org.springframework.amqp.core.AmqpAdminqueue - the queueignoreDeclarationExceptions is
true.@ManagedOperation(description="Declare a queue with a broker-generated name (this operation is not available remotely)") @Nullable public org.springframework.amqp.core.Queue declareQueue()
declareQueue in interface org.springframework.amqp.core.AmqpAdminignoreDeclarationExceptions
is true.@ManagedOperation(description="Delete a queue from the broker") public boolean deleteQueue(java.lang.String queueName)
deleteQueue in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Delete a queue from the broker if unused and empty (when corresponding arguments are true")
public void deleteQueue(java.lang.String queueName,
boolean unused,
boolean empty)
deleteQueue in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Purge a queue and optionally don\'t wait for the purge to occur")
public void purgeQueue(java.lang.String queueName,
boolean noWait)
purgeQueue in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Purge a queue and return the number of messages purged") public int purgeQueue(java.lang.String queueName)
purgeQueue in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Declare a binding on the broker (this operation is not available remotely)") public void declareBinding(org.springframework.amqp.core.Binding binding)
declareBinding in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Remove a binding from the broker (this operation is not available remotely)") public void removeBinding(org.springframework.amqp.core.Binding binding)
removeBinding in interface org.springframework.amqp.core.AmqpAdmin@ManagedOperation(description="Get queue name, message count and consumer count") public java.util.Properties getQueueProperties(java.lang.String queueName)
QUEUE_NAME, QUEUE_MESSAGE_COUNT,
QUEUE_CONSUMER_COUNT, or null if the queue doesn't exist.getQueueProperties in interface org.springframework.amqp.core.AmqpAdminpublic org.springframework.amqp.core.QueueInformation getQueueInfo(java.lang.String queueName)
getQueueInfo in interface org.springframework.amqp.core.AmqpAdminpublic void setExplicitDeclarationsOnly(boolean explicitDeclarationsOnly)
Declarable beans that are explicitly configured
to be declared by this admin.explicitDeclarationsOnly - true to ignore beans with no admin declaration
configuration.public boolean isRedeclareManualDeclarations()
Declarables via admin methods.public void setRedeclareManualDeclarations(boolean redeclareManualDeclarations)
Declarables via admin
methods. When a queue or exhange is deleted, it will not longer be recovered, nor
will any corresponding bindings.redeclareManualDeclarations - true to redeclare.declareQueue(Queue),
declareExchange(Exchange),
declareBinding(Binding),
deleteQueue(String),
deleteExchange(String),
removeBinding(Binding),
resetAllManualDeclarations()public void setRetryTemplate(@Nullable
org.springframework.retry.support.RetryTemplate retryTemplate)
null. Note that this
retry is at the macro level - all declarations will be retried within the scope of
this template. If you supplied a RabbitTemplate that is configured with a
RetryTemplate, its template will retry each individual declaration.retryTemplate - the retry template.public void setBeanName(java.lang.String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic java.lang.String getBeanName()
public boolean isAutoStartup()
public void afterPropertiesSet()
autoStartup is set to true, registers a callback on the
ConnectionFactory to declare all exchanges and queues in the enclosing application context. If the
callback fails then it may cause other clients of the connection factory to fail, but since only exchanges,
queues and bindings are declared failure is not expected.afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanInitializingBean.afterPropertiesSet(),
initialize()public void initialize()
initialize in interface org.springframework.amqp.core.AmqpAdminpublic void resetAllManualDeclarations()
declare*() methods.setRedeclareManualDeclarations(boolean)