@ManagedResource(description="Admin Tasks") public class RabbitAdmin extends Object implements AmqpAdmin, ApplicationContextAware, ApplicationEventPublisherAware, BeanNameAware, InitializingBean
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_EXCHANGE_NAME
The default exchange name.
|
protected Log |
logger
Logger available to subclasses.
|
static Object |
QUEUE_CONSUMER_COUNT
Property key for the consumer count in the
Properties returned by
getQueueProperties(String). |
static Object |
QUEUE_MESSAGE_COUNT
Property key for the message count in the
Properties returned by
getQueueProperties(String). |
static 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(Binding binding)
Declare a binding of a queue to an exchange.
|
void |
declareExchange(Exchange exchange)
Declare an exchange.
|
Queue |
declareQueue()
Declares a server-named exclusive, autodelete, non-durable queue.
|
String |
declareQueue(Queue queue)
Declare the given queue.
|
boolean |
deleteExchange(String exchangeName)
Delete an exchange.
|
boolean |
deleteQueue(String queueName)
Delete a queue, without regard for whether it is in use or has messages on it.
|
void |
deleteQueue(String queueName,
boolean unused,
boolean empty)
Delete a queue.
|
String |
getBeanName() |
DeclarationExceptionEvent |
getLastDeclarationExceptionEvent() |
QueueInformation |
getQueueInfo(String queueName)
Returns information about the queue, if it exists.
|
Properties |
getQueueProperties(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() |
int |
purgeQueue(String queueName)
Purges the contents of the given queue.
|
void |
purgeQueue(String queueName,
boolean noWait)
Purges the contents of the given queue.
|
void |
removeBinding(Binding binding)
Remove a binding of a queue to an exchange.
|
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setAutoStartup(boolean autoStartup) |
void |
setBeanName(String name) |
void |
setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions) |
void |
setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
Set a retry template for auto declarations.
|
void |
setTaskExecutor(TaskExecutor taskExecutor)
Set a task executor to use for async operations.
|
public static final String DEFAULT_EXCHANGE_NAME
public static final Object QUEUE_NAME
Properties returned by
getQueueProperties(String).public static final Object QUEUE_MESSAGE_COUNT
Properties returned by
getQueueProperties(String).public static final Object QUEUE_CONSUMER_COUNT
Properties returned by
getQueueProperties(String).protected final 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(ApplicationContext applicationContext)
setApplicationContext in interface ApplicationContextAwarepublic void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic void setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions)
public DeclarationExceptionEvent getLastDeclarationExceptionEvent()
DeclarationExceptionEvent that was detected in this admin.public void setTaskExecutor(TaskExecutor taskExecutor)
purgeQueue(String, boolean).taskExecutor - the executor to use.public RabbitTemplate getRabbitTemplate()
public void declareExchange(Exchange exchange)
AmqpAdmindeclareExchange in interface AmqpAdminexchange - the exchange to declare.@ManagedOperation(description="Delete an exchange from the broker") public boolean deleteExchange(String exchangeName)
AmqpAdmindeleteExchange in interface AmqpAdminexchangeName - the name of the exchange@ManagedOperation(description="Declare a queue on the broker (this operation is not available remotely)") @Nullable public String declareQueue(Queue queue)
declareQueue in interface AmqpAdminqueue - the queueignoreDeclarationExceptions is
true.@ManagedOperation(description="Declare a queue with a broker-generated name (this operation is not available remotely)") @Nullable public Queue declareQueue()
declareQueue in interface AmqpAdminignoreDeclarationExceptions
is true.@ManagedOperation(description="Delete a queue from the broker") public boolean deleteQueue(String queueName)
AmqpAdmindeleteQueue in interface AmqpAdminqueueName - the name of the queue.@ManagedOperation(description="Delete a queue from the broker if unused and empty (when corresponding arguments are true") public void deleteQueue(String queueName, boolean unused, boolean empty)
AmqpAdmindeleteQueue in interface AmqpAdminqueueName - the name of the queue.unused - true if the queue should be deleted only if not in use.empty - true if the queue should be deleted only if empty.@ManagedOperation(description="Purge a queue and optionally don\'t wait for the purge to occur") public void purgeQueue(String queueName, boolean noWait)
AmqpAdminpurgeQueue in interface AmqpAdminqueueName - the name of the queue.noWait - true to not await completion of the purge.@ManagedOperation(description="Purge a queue and return the number of messages purged") public int purgeQueue(String queueName)
AmqpAdminpurgeQueue in interface AmqpAdminqueueName - the name of the queue.@ManagedOperation(description="Declare a binding on the broker (this operation is not available remotely)") public void declareBinding(Binding binding)
AmqpAdmindeclareBinding in interface AmqpAdminbinding - a description of the binding to declare.@ManagedOperation(description="Remove a binding from the broker (this operation is not available remotely)") public void removeBinding(Binding binding)
AmqpAdminremoveBinding in interface AmqpAdminbinding - a description of the binding to remove.@ManagedOperation(description="Get queue name, message count and consumer count") public Properties getQueueProperties(String queueName)
QUEUE_NAME, QUEUE_MESSAGE_COUNT,
QUEUE_CONSUMER_COUNT, or null if the queue doesn't exist.getQueueProperties in interface AmqpAdminqueueName - the name of the queue.public QueueInformation getQueueInfo(String queueName)
AmqpAdmingetQueueInfo in interface AmqpAdminqueueName - the name of the queue.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(String name)
setBeanName in interface BeanNameAwarepublic 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 InitializingBeanInitializingBean.afterPropertiesSet(),
initialize()public void initialize()
initialize in interface AmqpAdmin