Class Client


  • public class Client
    extends Object
    • Field Detail

      • rootUri

        protected final URI rootUri
    • Method Detail

      • getOverview

        public OverviewResponse getOverview()
        Returns:
        cluster state overview
      • alivenessTest

        public boolean alivenessTest​(String vhost)
        Performs a basic node aliveness check: declares a queue, publishes a message that routes to it, consumes it, cleans up.
        Parameters:
        vhost - vhost to use to perform aliveness check in
        Returns:
        true if the check succeeded
      • whoAmI

        public CurrentUserDetails whoAmI()
        Returns:
        information about the user used by this client instance
      • getNodes

        public List<NodeInfo> getNodes()
        Retrieves state and metrics information for all nodes in the cluster.
        Returns:
        list of nodes in the cluster
      • getNode

        public NodeInfo getNode​(String name)
        Retrieves state and metrics information for individual node.
        Parameters:
        name - node name
        Returns:
        node information
      • getConnections

        public List<ConnectionInfo> getConnections()
        Retrieves state and metrics information for all client connections across the cluster.
        Returns:
        list of connections across the cluster
      • getConnections

        public Page<ConnectionInfo> getConnections​(QueryParameters queryParameters)
        Retrieves state and metrics information for all client connections across the cluster using query parameters
        Parameters:
        queryParameters -
        Returns:
        list of connections across the cluster
      • getConnection

        public ConnectionInfo getConnection​(String name)
        Retrieves state and metrics information for individual client connection.
        Parameters:
        name - connection name
        Returns:
        connection information
      • getConnectionsOfUser

        public List<UserConnectionInfo> getConnectionsOfUser​(String username)
        Lists connection that belong to a specific user (used the provided username during authentication).
        Parameters:
        username - username
      • closeConnection

        public void closeConnection​(String name)
        Forcefully closes individual connection. The client will receive a connection.close method frame.
        Parameters:
        name - connection name
      • closeAllConnectionsOfUser

        public void closeAllConnectionsOfUser​(String username)
        Forcefully closes all connections that belong to a specific user (used the provided username during authentication). The client will receive a connection.close method frame.
        Parameters:
        username - username
      • closeConnection

        public void closeConnection​(String name,
                                    String reason)
        Forcefully closes individual connection with a user-provided message. The client will receive a connection.close method frame.
        Parameters:
        name - connection name
        reason - the reason of closing
      • getConsumers

        public List<ConsumerDetails> getConsumers()
        Retrieves state and metrics information for all consumers across the cluster.
        Returns:
        list of consumers across the cluster
      • getConsumers

        public List<ConsumerDetails> getConsumers​(String vhost)
        Retrieves state and metrics information for all consumers across an individual virtual host.
        Parameters:
        vhost - name of the virtual host
        Returns:
        list of consumers in the virtual host (across all nodes)
      • getChannels

        public List<ChannelInfo> getChannels()
        Retrieves state and metrics information for all channels across the cluster.
        Returns:
        list of channels across the cluster
      • getChannels

        public Page<ChannelInfo> getChannels​(QueryParameters queryParameters)
        Retrieves state and metrics information for all channels across the cluster. using query parameters
        Parameters:
        queryParameters -
        Returns:
        list of channels across the cluster
      • getChannels

        public List<ChannelInfo> getChannels​(String connectionName)
        Retrieves state and metrics information for all channels on individual connection.
        Parameters:
        connectionName - the connection name to retrieve channels
        Returns:
        list of channels on the connection
      • getChannel

        public ChannelInfo getChannel​(String name)
        Retrieves state and metrics information for individual channel.
        Parameters:
        name - channel name
        Returns:
        channel information
      • createVhost

        public void createVhost​(String name,
                                boolean tracing,
                                String description,
                                String... tags)
        Create a virtual host with name, tracing flag, and metadata. Note metadata (description and tags) are supported as of RabbitMQ 3.8.
        Parameters:
        name - name of the virtual host
        tracing - whether tracing is enabled or not
        description - virtual host description (requires RabbitMQ 3.8 or more)
        tags - virtual host tags (requires RabbitMQ 3.8 or more)
        Since:
        3.4.0
      • createVhost

        public void createVhost​(String name,
                                String description,
                                String... tags)
        Create a virtual host with name and metadata. Note metadata (description and tags) are supported as of RabbitMQ 3.8.
        Parameters:
        name - name of the virtual host
        description - virtual host description (requires RabbitMQ 3.8 or more)
        tags - virtual host tags (requires RabbitMQ 3.8 or more)
        Since:
        3.4.0
      • createVhost

        public void createVhost​(String name,
                                boolean tracing)
        Create a virtual host with name and tracing flag.
        Parameters:
        name - name of the virtual host
        tracing - whether tracing is enabled or not
        Since:
        3.4.0
      • createVhost

        public void createVhost​(String name)
      • deleteVhost

        public void deleteVhost​(String name)
      • deleteExchange

        public void deleteExchange​(String vhost,
                                   String name)
      • publish

        public boolean publish​(String vhost,
                               String exchange,
                               String routingKey,
                               OutboundMessage outboundMessage)
        Publishes a message to an exchange.

        DO NOT USE THIS METHOD IN PRODUCTION. The HTTP API has to create a new TCP connection for each message published, which is highly suboptimal.

        Use this method for test or development code only. In production, use AMQP 0-9-1 or any other messaging protocol that uses a long-lived connection.

        Parameters:
        vhost - the virtual host to use
        exchange - the target exchange
        routingKey - the routing key to use
        outboundMessage - the message to publish
        Returns:
        true if message has been routed to at least a queue, false otherwise
        Since:
        3.4.0
      • purgeQueue

        public void purgeQueue​(String vhost,
                               String name)
      • deleteQueue

        public void deleteQueue​(String vhost,
                                String name)
      • get

        public List<InboundMessage> get​(String vhost,
                                        String queue,
                                        int count,
                                        GetAckMode ackMode,
                                        GetEncoding encoding,
                                        int truncate)
        Get messages from a queue. DO NOT USE THIS METHOD IN PRODUCTION. Getting messages with the HTTP API is intended for diagnostics or tests. It does not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.
        Parameters:
        vhost - the virtual host the target queue is in
        queue - the queue to consume from
        count - the maximum number of messages to get
        ackMode - determines whether the messages will be removed from the queue
        encoding - the expected encoding of the message payload
        truncate - to truncate the message payload if it is larger than the size given (in bytes), -1 means no truncation
        Returns:
        the list of messages
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • get

        public List<InboundMessage> get​(String vhost,
                                        String queue,
                                        int count,
                                        GetAckMode ackMode,
                                        GetEncoding encoding)
        Get messages from a queue, with no limit for message payload truncation. DO NOT USE THIS METHOD IN PRODUCTION. Getting messages with the HTTP API is intended for diagnostics or tests. It does not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.
        Parameters:
        vhost - the virtual host the target queue is in
        queue - the queue to consume from
        count - the maximum number of messages to get
        ackMode - determines whether the messages will be removed from the queue
        encoding - the expected encoding of the message payload
        Returns:
        the list of messages
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • get

        public InboundMessage get​(String vhost,
                                  String queue)
        Get one message from a queue and requeue it. DO NOT USE THIS METHOD IN PRODUCTION. Getting messages with the HTTP API is intended for diagnostics or tests. It does not implement reliable delivery and so should be treated as a sysadmin's tool rather than a general API for messaging.
        Parameters:
        vhost - the virtual host the target queue is in
        queue - the queue to consume from
        Returns:
        the message, null if the queue is empty
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • deletePolicy

        public void deletePolicy​(String vhost,
                                 String name)
      • deleteOperatorPolicy

        public void deleteOperatorPolicy​(String vhost,
                                         String name)
      • createUser

        public void createUser​(String username,
                               char[] password,
                               List<String> tags)
      • createUserWithPasswordHash

        public void createUserWithPasswordHash​(String username,
                                               char[] passwordHash,
                                               List<String> tags)
      • updateUser

        public void updateUser​(String username,
                               char[] password,
                               List<String> tags)
      • deleteUser

        public void deleteUser​(String username)
      • clearPermissions

        public void clearPermissions​(String vhost,
                                     String username)
      • clearTopicPermissions

        public void clearTopicPermissions​(String vhost,
                                          String username)
      • getBindingsBySource

        public List<BindingInfo> getBindingsBySource​(String vhost,
                                                     String exchange)
        Returns a list of bindings where provided exchange is the source (other things are bound to it).
        Parameters:
        vhost - vhost of the exchange
        exchange - source exchange name
        Returns:
        list of bindings
      • getExchangeBindingsByDestination

        public List<BindingInfo> getExchangeBindingsByDestination​(String vhost,
                                                                  String exchange)
        Returns a list of bindings where provided exchange is the destination (it is bound to another exchange).
        Parameters:
        vhost - vhost of the exchange
        exchange - destination exchange name
        Returns:
        list of bindings
      • getQueueBindings

        public List<BindingInfo> getQueueBindings​(String vhost,
                                                  String queue)
        Returns a list of bindings where provided queue is the destination.
        Parameters:
        vhost - vhost of the exchange
        queue - destination queue name
        Returns:
        list of bindings
      • bindQueue

        public void bindQueue​(String vhost,
                              String queue,
                              String exchange,
                              String routingKey)
        Binds a queue to an exchange.
        Parameters:
        vhost - virtual host the queue and exchange are in
        queue - the queue name
        exchange - the exchange name
        routingKey - the routing key to use
      • bindQueue

        public void bindQueue​(String vhost,
                              String queue,
                              String exchange,
                              String routingKey,
                              Map<String,​Object> args)
        Binds a queue to an exchange.
        Parameters:
        vhost - virtual host the queue and exchange are in
        queue - the queue name
        exchange - the exchange name
        routingKey - the routing key to use
        args - additional map of arguments (used by some exchange types)
      • unbindQueue

        public void unbindQueue​(String vhost,
                                String queue,
                                String exchange,
                                String routingKey)
        Unbinds a queue from an exchange.
        Parameters:
        vhost - virtual host the queue and exchange are in
        queue - the queue name
        exchange - the exchange name
        routingKey - the routing key used when binding
      • bindExchange

        public void bindExchange​(String vhost,
                                 String destination,
                                 String source,
                                 String routingKey)
        Binds a destination exchange to a source one.
        Parameters:
        vhost - virtual host the exchanges are in
        destination - the destination exchange name
        source - the source exchange name
        routingKey - the routing key to use
      • bindExchange

        public void bindExchange​(String vhost,
                                 String destination,
                                 String source,
                                 String routingKey,
                                 Map<String,​Object> args)
        Binds a destination exchange to a source one.
        Parameters:
        vhost - virtual host the exchanges are in
        destination - the destination exchange name
        source - the source exchange name
        routingKey - the routing key to use
        args - additional map of arguments (used by some exchange types)
      • unbindExchange

        public void unbindExchange​(String vhost,
                                   String destination,
                                   String source,
                                   String routingKey)
        Unbinds a destination exchange from a source one.
        Parameters:
        vhost - virtual host the exchanges are in
        destination - the destination exchange name
        source - the source exchange name
        routingKey - the routing key used when binding
      • getClusterName

        public ClusterId getClusterName()
      • setClusterName

        public void setClusterName​(String name)
      • getExtensions

        public List<Map> getExtensions()
      • declareShovel

        public void declareShovel​(String vhost,
                                  ShovelInfo info)
        Declares a shovel.
        Parameters:
        vhost - virtual host where to declare the shovel
        info - Shovel info.
      • getShovels

        public List<ShovelInfo> getShovels()
        Returns virtual host shovels.
        Returns:
        Shovels.
      • getShovels

        public List<ShovelInfo> getShovels​(String vhost)
        Returns virtual host shovels.
        Parameters:
        vhost - Virtual host from where search shovels.
        Returns:
        Shovels.
      • getShovelsStatus

        public List<ShovelStatus> getShovelsStatus()
        Returns virtual host shovels.
        Returns:
        Shovels.
      • getShovelsStatus

        public List<ShovelStatus> getShovelsStatus​(String vhost)
        Returns virtual host shovels.
        Parameters:
        vhost - Virtual host from where search shovels.
        Returns:
        Shovels.
      • deleteShovel

        public void deleteShovel​(String vhost,
                                 String shovelname)
        Deletes the specified shovel from specified virtual host.
        Parameters:
        vhost - virtual host from where to delete the shovel
        shovelname - Shovel to be deleted.
      • declareUpstream

        public void declareUpstream​(String vhost,
                                    String name,
                                    UpstreamDetails details)
        Declares an upstream
        Parameters:
        vhost - virtual host for which to declare the upstream
        name - name of the upstream to declare
        details - upstream arguments
      • deleteUpstream

        public void deleteUpstream​(String vhost,
                                   String name)
        Deletes an upstream
        Parameters:
        vhost - virtual host for which to delete the upstream
        name - name of the upstream to delete
      • getUpstreams

        public List<UpstreamInfo> getUpstreams()
        Returns a list of upstreams for "/" virtual host
        Returns:
        upstream info
      • getUpstreams

        public List<UpstreamInfo> getUpstreams​(String vhost)
        Returns a list of upstreams
        Parameters:
        vhost - virtual host the upstreams are in.
        Returns:
        upstream info
      • declareUpstreamSet

        public void declareUpstreamSet​(String vhost,
                                       String name,
                                       List<UpstreamSetDetails> details)
        Declares an upstream set.
        Parameters:
        vhost - virtual host for which to declare the upstream set
        name - name of the upstream set to declare
        details - upstream set arguments
      • deleteUpstreamSet

        public void deleteUpstreamSet​(String vhost,
                                      String name)
        Deletes an upstream set
        Parameters:
        vhost - virtual host for which to delete the upstream set
        name - name of the upstream set to delete
      • getUpstreamSets

        public List<UpstreamSetInfo> getUpstreamSets()
        Returns a list of upstream sets for "/" virtual host
        Returns:
        upstream info
      • getUpstreamSets

        public List<UpstreamSetInfo> getUpstreamSets​(String vhost)
        Returns a list of upstream sets.
        Parameters:
        vhost - Virtual host from where to get upstreams.
        Returns:
        upstream set info
      • getVhostLimits

        public List<VhostLimits> getVhostLimits()
        Returns the limits (max queues and connections) for all virtual hosts.
        Returns:
        the limits
        Since:
        3.7.0
      • getVhostLimits

        public VhostLimits getVhostLimits​(String vhost)
        Returns the limits (max queues and connections) for a given virtual host.
        Parameters:
        vhost - the virtual host
        Returns:
        the limits for this virtual host
        Since:
        3.7.0
      • limitMaxNumberOfConnections

        public void limitMaxNumberOfConnections​(String vhost,
                                                int limit)
        Sets the max number (limit) of connections for a virtual host.
        Parameters:
        vhost - the virtual host
        limit - the max number of connections allowed
        Since:
        3.7.0
      • limitMaxNumberOfQueues

        public void limitMaxNumberOfQueues​(String vhost,
                                           int limit)
        Sets the max number (limit) of queues for a virtual host.
        Parameters:
        vhost - the virtual host
        limit - the max number of queues allowed
        Since:
        3.7.0
      • clearMaxConnectionsLimit

        public void clearMaxConnectionsLimit​(String vhost)
        Clears the connection limit for a virtual host.
        Parameters:
        vhost - the virtual host
        Since:
        3.7.0
      • clearMaxQueuesLimit

        public void clearMaxQueuesLimit​(String vhost)
        Clears the queue limit for a virtual host.
        Parameters:
        vhost - the virtual host
        Since:
        3.7.0