Spring AMQP

org.springframework.amqp.rabbit.admin
Class RabbitBrokerAdmin

java.lang.Object
  extended by org.springframework.amqp.rabbit.admin.RabbitBrokerAdmin
All Implemented Interfaces:
RabbitBrokerOperations

public class RabbitBrokerAdmin
extends Object
implements RabbitBrokerOperations

Rabbit broker administration. Features:

Depending on your platform, to start the broker you might need to set some environment properties. The most common are available via constructors or setters in this class (e.g. RABBITMQ_LOG_BASE). All others you can set via the OS (any setting that RabbtMQ allows in its startup script), and some work via System properties as special convenience cases ( ERLANG_HOME and RABBITMQ_HOME ).

Author:
Mark Pollack, Dave Syer, Helena Edelson

Field Summary
protected  org.apache.commons.logging.Log logger
          Logger available to subclasses
 
Constructor Summary
RabbitBrokerAdmin()
           
RabbitBrokerAdmin(String nodeName)
          Create an instance by supplying the erlang node name (e.g.
RabbitBrokerAdmin(String nodeName, int port)
          Create an instance by supplying the erlang node name and port number.
RabbitBrokerAdmin(String nodeName, int port, String cookie)
          Create an instance by supplying the erlang node name, port number and cookie (unique string).
RabbitBrokerAdmin(String nodeName, String cookie)
          Create an instance by supplying the erlang node name and cookie (unique string).
 
Method Summary
 void addUser(String username, String password)
           
 int addVhost(String vhostPath)
           
 void changeUserPassword(String username, String newPassword)
           
 void clearPermissions(String username)
           
 void clearPermissions(String username, String vhostPath)
           
protected  void createErlangTemplate(ConnectionFactory otpConnectionFactory)
           
 void deleteUser(String username)
           
 int deleteVhost(String vhostPath)
           
 void forceResetNode()
          The forceResetNode command differs from RabbitBrokerOperations.resetNode() in that it resets the node unconditionally, regardless of the current management database state and cluster configuration.
 List<QueueInfo> getQueues()
           
 List<QueueInfo> getQueues(String virtualHost)
           
 RabbitStatus getStatus()
          Returns the status of the node.
protected  void initializeDefaultErlangTemplate()
           
 List<String> listPermissions()
           
 List<String> listPermissions(String vhostPath)
           
 List<String> listUserPermissions(String username)
           
 List<String> listUsers()
           
 void recoverAsync(boolean requeue)
           
 void resetNode()
          Removes the node from any cluster it belongs to, removes all data from the management database, such as configured users and vhosts, and deletes all persistent messages.
 void setEncoding(String encoding)
          The encoding to use for converting host names to byte arrays (which is needed on the remote side).
 void setModuleAdapter(Map<String,String> moduleAdapter)
          Allows users to adapt Erlang RPC (module, function) pairs to older, or different, versions of the broker than the current target.
 void setPermissions(String username, Pattern configure, Pattern read, Pattern write)
           
 void setPermissions(String username, Pattern configure, Pattern read, Pattern write, String vhostPath)
           
 void setRabbitLogBaseDirectory(String rabbitLogBaseDirectory)
          The location of RABBITMQ_LOG_BASE to override the system default (which may be owned by another user).
 void setRabbitMnesiaBaseDirectory(String rabbitMnesiaBaseDirectory)
          The location of RABBITMQ_MNESIA_BASE to override the system default (which may be owned by another user).
 void setStartupTimeout(long timeout)
          Timeout (milliseconds) to wait for the broker to come up.
 void startBrokerApplication()
          Starts the RabbitMQ application on an already running node.
 void startNode()
          Starts the Erlang node where RabbitMQ is running by shelling out to the directory specified by RABBITMQ_HOME and executing the standard named start script.
 void stopBrokerApplication()
          Stops the RabbitMQ application, leaving the Erlang node running.
 void stopNode()
          Stops the halts the Erlang node on which RabbitMQ is running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses

Constructor Detail

RabbitBrokerAdmin

public RabbitBrokerAdmin()

RabbitBrokerAdmin

public RabbitBrokerAdmin(String nodeName)
Create an instance by supplying the erlang node name (e.g. "rabbit@myserver"), or simply the hostname (if the alive name is "rabbit").

Parameters:
nodeName - the node name or hostname to use

RabbitBrokerAdmin

public RabbitBrokerAdmin(String nodeName,
                         String cookie)
Create an instance by supplying the erlang node name and cookie (unique string).

Parameters:
nodeName - the node name or hostname to use
cookie - the cookie value to use

RabbitBrokerAdmin

public RabbitBrokerAdmin(String nodeName,
                         int port)
Create an instance by supplying the erlang node name and port number. Use this on a UN*X system if you want to run the broker as a user without root privileges, supplying values that do not clash with the default broker (usually "rabbit@<servername>" and 5672). If, as well as managing an existing broker, you need to start the broker process, you will also need to set RABBITMQ_LOG_BASE and #setRabbitMnesiaBaseDirectory(String)RABBITMQ_MNESIA_BASE to point to writable directories).

Parameters:
nodeName - the node name or hostname to use
port - the port number (overriding the default which is 5672)

RabbitBrokerAdmin

public RabbitBrokerAdmin(String nodeName,
                         int port,
                         String cookie)
Create an instance by supplying the erlang node name, port number and cookie (unique string). If the node name does not contain an @ character, it will be prepended with an alivename rabbit@ (interpreting the supplied value as just the hostname).

Parameters:
nodeName - the node name or hostname to use
port - the port number (overriding the default which is 5672)
cookie - the cookie value to use
Method Detail

setRabbitLogBaseDirectory

public void setRabbitLogBaseDirectory(String rabbitLogBaseDirectory)
The location of RABBITMQ_LOG_BASE to override the system default (which may be owned by another user). Only needed for launching the broker process. Can also be set as a system property.

Parameters:
rabbitLogBaseDirectory - the rabbit log base directory to set

setRabbitMnesiaBaseDirectory

public void setRabbitMnesiaBaseDirectory(String rabbitMnesiaBaseDirectory)
The location of RABBITMQ_MNESIA_BASE to override the system default (which may be owned by another user). Only needed for launching the broker process. Can also be set as a system property.

Parameters:
rabbitMnesiaBaseDirectory - the rabbit Mnesia base directory to set

setEncoding

public void setEncoding(String encoding)
The encoding to use for converting host names to byte arrays (which is needed on the remote side).

Parameters:
encoding - the encoding to use (default UTF-8)

setStartupTimeout

public void setStartupTimeout(long timeout)
Timeout (milliseconds) to wait for the broker to come up. If the provided timeout is greater than zero then we wait for that period for the broker to be ready. If it is not ready after that time the process is stopped. Defaults to 0 (no wait).

Parameters:
timeout - the timeout value to set in milliseconds

setModuleAdapter

public void setModuleAdapter(Map<String,String> moduleAdapter)
Allows users to adapt Erlang RPC (module, function) pairs to older, or different, versions of the broker than the current target. The map is from String to String in the form input_module%input_function -> output_module%output_function (using a % separator).

Parameters:
moduleAdapter - the module adapter to set

getQueues

public List<QueueInfo> getQueues()
Specified by:
getQueues in interface RabbitBrokerOperations

getQueues

public List<QueueInfo> getQueues(String virtualHost)
Specified by:
getQueues in interface RabbitBrokerOperations

addUser

@ManagedOperation
public void addUser(String username,
                                     String password)
Specified by:
addUser in interface RabbitBrokerOperations

deleteUser

@ManagedOperation
public void deleteUser(String username)
Specified by:
deleteUser in interface RabbitBrokerOperations

changeUserPassword

@ManagedOperation
public void changeUserPassword(String username,
                                                String newPassword)
Specified by:
changeUserPassword in interface RabbitBrokerOperations

listUsers

@ManagedOperation
public List<String> listUsers()
Specified by:
listUsers in interface RabbitBrokerOperations

addVhost

public int addVhost(String vhostPath)
Specified by:
addVhost in interface RabbitBrokerOperations

deleteVhost

public int deleteVhost(String vhostPath)
Specified by:
deleteVhost in interface RabbitBrokerOperations

setPermissions

public void setPermissions(String username,
                           Pattern configure,
                           Pattern read,
                           Pattern write)
Specified by:
setPermissions in interface RabbitBrokerOperations

setPermissions

public void setPermissions(String username,
                           Pattern configure,
                           Pattern read,
                           Pattern write,
                           String vhostPath)
Specified by:
setPermissions in interface RabbitBrokerOperations

clearPermissions

public void clearPermissions(String username)
Specified by:
clearPermissions in interface RabbitBrokerOperations

clearPermissions

public void clearPermissions(String username,
                             String vhostPath)
Specified by:
clearPermissions in interface RabbitBrokerOperations

listPermissions

public List<String> listPermissions()
Specified by:
listPermissions in interface RabbitBrokerOperations

listPermissions

public List<String> listPermissions(String vhostPath)
Specified by:
listPermissions in interface RabbitBrokerOperations

listUserPermissions

public List<String> listUserPermissions(String username)
Specified by:
listUserPermissions in interface RabbitBrokerOperations

startBrokerApplication

@ManagedOperation
public void startBrokerApplication()
Description copied from interface: RabbitBrokerOperations
Starts the RabbitMQ application on an already running node. This command is typically run after performing other management actions that required the RabbitMQ application to be stopped, e.g. reset.

Specified by:
startBrokerApplication in interface RabbitBrokerOperations

stopBrokerApplication

@ManagedOperation
public void stopBrokerApplication()
Description copied from interface: RabbitBrokerOperations
Stops the RabbitMQ application, leaving the Erlang node running.

Specified by:
stopBrokerApplication in interface RabbitBrokerOperations

startNode

@ManagedOperation
public void startNode()
Description copied from interface: RabbitBrokerOperations
Starts the Erlang node where RabbitMQ is running by shelling out to the directory specified by RABBITMQ_HOME and executing the standard named start script. It spawns the shell command execution into its own thread.

Specified by:
startNode in interface RabbitBrokerOperations

stopNode

@ManagedOperation
public void stopNode()
Description copied from interface: RabbitBrokerOperations
Stops the halts the Erlang node on which RabbitMQ is running. To restart the node you will need to execute the start script from a command line or via other means.

Specified by:
stopNode in interface RabbitBrokerOperations

resetNode

@ManagedOperation
public void resetNode()
Description copied from interface: RabbitBrokerOperations
Removes the node from any cluster it belongs to, removes all data from the management database, such as configured users and vhosts, and deletes all persistent messages.

For RabbitBrokerOperations.resetNode() and RabbitBrokerOperations.forceResetNode() to succeed the RabbitMQ application must have been stopped, e.g. RabbitBrokerOperations.stopBrokerApplication()

Specified by:
resetNode in interface RabbitBrokerOperations

forceResetNode

@ManagedOperation
public void forceResetNode()
Description copied from interface: RabbitBrokerOperations
The forceResetNode command differs from RabbitBrokerOperations.resetNode() in that it resets the node unconditionally, regardless of the current management database state and cluster configuration. It should only be used as a last resort if the database or cluster configuration has been corrupted.

For RabbitBrokerOperations.resetNode() and RabbitBrokerOperations.forceResetNode() to succeed the RabbitMQ application must have been stopped, e.g. RabbitBrokerOperations.stopBrokerApplication()

Specified by:
forceResetNode in interface RabbitBrokerOperations

getStatus

@ManagedOperation
public RabbitStatus getStatus()
Description copied from interface: RabbitBrokerOperations
Returns the status of the node.

Specified by:
getStatus in interface RabbitBrokerOperations
Returns:
status of the node.

recoverAsync

public void recoverAsync(boolean requeue)
Specified by:
recoverAsync in interface RabbitBrokerOperations

initializeDefaultErlangTemplate

protected void initializeDefaultErlangTemplate()

createErlangTemplate

protected void createErlangTemplate(ConnectionFactory otpConnectionFactory)

Spring AMQP

Copyright © 2011. All Rights Reserved.