Class RabbitAdmin

java.lang.Object
org.springframework.amqp.rabbit.core.RabbitAdmin
All Implemented Interfaces:
org.springframework.amqp.core.AmqpAdmin, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware

@ManagedResource(description="Admin Tasks") public class RabbitAdmin extends 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
RabbitMQ implementation of portable AMQP administrative operations for AMQP >= 0.9.1.
  • Field Details

  • Constructor Details

    • RabbitAdmin

      public RabbitAdmin(ConnectionFactory connectionFactory)
      Construct an instance using the provided ConnectionFactory.
      Parameters:
      connectionFactory - the connection factory - must not be null.
    • RabbitAdmin

      public RabbitAdmin(RabbitTemplate rabbitTemplate)
      Construct an instance using the provided 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.
      Parameters:
      rabbitTemplate - the template - must not be null and must have a connection factory.
      Since:
      2.0
  • Method Details

    • setAutoStartup

      public void setAutoStartup(boolean autoStartup)
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • setIgnoreDeclarationExceptions

      public void setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions)
    • getLastDeclarationExceptionEvent

      public DeclarationExceptionEvent getLastDeclarationExceptionEvent()
      Returns:
      the last DeclarationExceptionEvent that was detected in this admin.
      Since:
      1.6
    • setTaskExecutor

      public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
      Set a task executor to use for async operations. Currently only used with purgeQueue(String, boolean).
      Parameters:
      taskExecutor - the executor to use.
      Since:
      2.1
    • getRabbitTemplate

      public RabbitTemplate getRabbitTemplate()
    • declareExchange

      public void declareExchange(org.springframework.amqp.core.Exchange exchange)
      Specified by:
      declareExchange in interface org.springframework.amqp.core.AmqpAdmin
    • deleteExchange

      @ManagedOperation(description="Delete an exchange from the broker") public boolean deleteExchange(String exchangeName)
      Specified by:
      deleteExchange in interface org.springframework.amqp.core.AmqpAdmin
    • declareQueue

      @ManagedOperation(description="Declare a queue on the broker (this operation is not available remotely)") @Nullable public String declareQueue(org.springframework.amqp.core.Queue queue)
      Declare the given queue. If the queue doesn't have a value for 'name' property, the queue name will be generated by Broker and returned from this method. The declaredName property of the queue will be updated to reflect this value.
      Specified by:
      declareQueue in interface org.springframework.amqp.core.AmqpAdmin
      Parameters:
      queue - the queue
      Returns:
      the queue name if successful, null if not successful and ignoreDeclarationExceptions is true.
    • declareQueue

      @ManagedOperation(description="Declare a queue with a broker-generated name (this operation is not available remotely)") @Nullable public org.springframework.amqp.core.Queue declareQueue()
      Declares a server-named exclusive, autodelete, non-durable queue.
      Specified by:
      declareQueue in interface org.springframework.amqp.core.AmqpAdmin
      Returns:
      the queue or null if an exception occurred and ignoreDeclarationExceptions is true.
    • deleteQueue

      @ManagedOperation(description="Delete a queue from the broker") public boolean deleteQueue(String queueName)
      Specified by:
      deleteQueue in interface org.springframework.amqp.core.AmqpAdmin
    • deleteQueue

      @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)
      Specified by:
      deleteQueue in interface org.springframework.amqp.core.AmqpAdmin
    • purgeQueue

      @ManagedOperation(description="Purge a queue and optionally don\'t wait for the purge to occur") public void purgeQueue(String queueName, boolean noWait)
      Specified by:
      purgeQueue in interface org.springframework.amqp.core.AmqpAdmin
    • purgeQueue

      @ManagedOperation(description="Purge a queue and return the number of messages purged") public int purgeQueue(String queueName)
      Specified by:
      purgeQueue in interface org.springframework.amqp.core.AmqpAdmin
    • declareBinding

      @ManagedOperation(description="Declare a binding on the broker (this operation is not available remotely)") public void declareBinding(org.springframework.amqp.core.Binding binding)
      Specified by:
      declareBinding in interface org.springframework.amqp.core.AmqpAdmin
    • removeBinding

      @ManagedOperation(description="Remove a binding from the broker (this operation is not available remotely)") public void removeBinding(org.springframework.amqp.core.Binding binding)
      Specified by:
      removeBinding in interface org.springframework.amqp.core.AmqpAdmin
    • getQueueProperties

      @ManagedOperation(description="Get queue name, message count and consumer count") public Properties getQueueProperties(String queueName)
      Returns 3 properties QUEUE_NAME, QUEUE_MESSAGE_COUNT, QUEUE_CONSUMER_COUNT, or null if the queue doesn't exist.
      Specified by:
      getQueueProperties in interface org.springframework.amqp.core.AmqpAdmin
    • getQueueInfo

      public org.springframework.amqp.core.QueueInformation getQueueInfo(String queueName)
      Specified by:
      getQueueInfo in interface org.springframework.amqp.core.AmqpAdmin
    • setExplicitDeclarationsOnly

      public void setExplicitDeclarationsOnly(boolean explicitDeclarationsOnly)
      Set to true to only declare Declarable beans that are explicitly configured to be declared by this admin.
      Parameters:
      explicitDeclarationsOnly - true to ignore beans with no admin declaration configuration.
      Since:
      2.1.9
    • isRedeclareManualDeclarations

      public 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. When this is true, it will also redeclare any manually declared Declarables via admin methods.
      Returns:
      true to redeclare.
      Since:
      2.4
    • setRedeclareManualDeclarations

      public 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. When this is true, it will also redeclare any manually declared Declarables via admin methods. When a queue or exhange is deleted, it will not longer be recovered, nor will any corresponding bindings.
      Parameters:
      redeclareManualDeclarations - true to redeclare.
      Since:
      2.4
      See Also:
    • setRetryTemplate

      public void setRetryTemplate(@Nullable org.springframework.retry.support.RetryTemplate retryTemplate)
      Set a retry template for auto declarations. There is a race condition with auto-delete, exclusive queues in that the queue might still exist for a short time, preventing the redeclaration. The default retry configuration will try 5 times with an exponential backOff starting at 1 second a multiplier of 2.0 and a max interval of 5 seconds. To disable retry, set the argument to 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.
      Parameters:
      retryTemplate - the retry template.
      Since:
      1.7.8
    • setBeanName

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getBeanName

      public String getBeanName()
    • isAutoStartup

      public boolean isAutoStartup()
    • afterPropertiesSet

      public 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. 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.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      See Also:
    • initialize

      public void initialize()
      Declares all the exchanges, queues and bindings in the enclosing application context, if any. It should be safe (but unnecessary) to call this method more than once.
      Specified by:
      initialize in interface org.springframework.amqp.core.AmqpAdmin
    • resetAllManualDeclarations

      public void resetAllManualDeclarations()
      Invoke this method to prevent the admin from recovering any declarations made by calls to declare*() methods.
      Since:
      2.4
      See Also: