Class ReactorNettyClient


  • public class ReactorNettyClient
    extends Object
    Reactive client based on Reactor Netty. Use the ReactorNettyClientOptions constructors for advanced settings, e.g. TLS, authentication other than HTTP basic, etc. The default settings for this class are the following:
    • HttpClient: created with the HttpClient.baseUrl(String).
    • ObjectMapper: DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES and MapperFeature.DEFAULT_VIEW_INCLUSION are disabled. JsonUtils.CURRENT_USER_DETAILS_DESERIALIZER_INSTANCE, JsonUtils.USER_INFO_DESERIALIZER_INSTANCE, JsonUtils.VHOST_LIMITS_DESERIALIZER_INSTANCE, and JsonUtils.CHANNEL_DETAILS_DESERIALIZER_INSTANCE set up.
    • Mono<String> token: basic HTTP authentication used for the authorization header.
    • BiConsumer<? super HttpRequest, ? super HttpResponse> responseCallback: 4xx and 5xx responses on GET requests throw HttpClientException and HttpServerException respectively.
    Since:
    2.1.0
    See Also:
    ReactorNettyClientOptions
    • Method Detail

      • createDefaultObjectMapper

        public static com.fasterxml.jackson.databind.ObjectMapper createDefaultObjectMapper()
      • createBasicAuthenticationToken

        public static reactor.core.publisher.Mono<String> createBasicAuthenticationToken​(String username,
                                                                                         String password)
      • basicAuthentication

        public static String basicAuthentication​(String username,
                                                 String password)
      • getOverview

        public reactor.core.publisher.Mono<OverviewResponse> getOverview()
      • getNodes

        public reactor.core.publisher.Flux<NodeInfo> getNodes()
      • getNode

        public reactor.core.publisher.Mono<NodeInfo> getNode​(String name)
      • getConnections

        public reactor.core.publisher.Flux<ConnectionInfo> getConnections()
      • closeConnection

        public reactor.core.publisher.Mono<HttpResponse> closeConnection​(String name)
      • getConsumers

        public reactor.core.publisher.Flux<ConsumerDetails> getConsumers()
      • getPolicies

        public reactor.core.publisher.Flux<PolicyInfo> getPolicies()
      • getPolicies

        public reactor.core.publisher.Flux<PolicyInfo> getPolicies​(String vhost)
      • getChannels

        public reactor.core.publisher.Flux<ChannelInfo> getChannels()
      • getChannels

        public reactor.core.publisher.Flux<ChannelInfo> getChannels​(String connectionName)
      • getChannel

        public reactor.core.publisher.Mono<ChannelInfo> getChannel​(String name)
      • getVhosts

        public reactor.core.publisher.Flux<VhostInfo> getVhosts()
      • getVhost

        public reactor.core.publisher.Mono<VhostInfo> getVhost​(String name)
      • createVhost

        public reactor.core.publisher.Mono<HttpResponse> 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)
        Returns:
        response wrapped in Mono
        Since:
        3.4.0
      • createVhost

        public reactor.core.publisher.Mono<HttpResponse> 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)
        Returns:
        response wrapped in Mono
        Since:
        3.4.0
      • createVhost

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        response wrapped in Mono
        Since:
        3.4.0
      • createVhost

        public reactor.core.publisher.Mono<HttpResponse> createVhost​(String name)
      • deleteVhost

        public reactor.core.publisher.Mono<HttpResponse> deleteVhost​(String name)
      • getPermissionsIn

        public reactor.core.publisher.Flux<UserPermissions> getPermissionsIn​(String vhost)
      • getTopicPermissionsIn

        public reactor.core.publisher.Flux<TopicPermissions> getTopicPermissionsIn​(String vhost)
      • getUsers

        public reactor.core.publisher.Flux<UserInfo> getUsers()
      • getUser

        public reactor.core.publisher.Mono<UserInfo> getUser​(String username)
      • deleteUser

        public reactor.core.publisher.Mono<HttpResponse> deleteUser​(String username)
      • getPermissionsOf

        public reactor.core.publisher.Flux<UserPermissions> getPermissionsOf​(String username)
      • getTopicPermissionsOf

        public reactor.core.publisher.Flux<TopicPermissions> getTopicPermissionsOf​(String username)
      • createUserWithPasswordHash

        public reactor.core.publisher.Mono<HttpResponse> createUserWithPasswordHash​(String username,
                                                                                    char[] passwordHash,
                                                                                    List<String> tags)
      • getPermissions

        public reactor.core.publisher.Flux<UserPermissions> getPermissions()
      • clearPermissions

        public reactor.core.publisher.Mono<HttpResponse> clearPermissions​(String vhost,
                                                                          String username)
      • getTopicPermissions

        public reactor.core.publisher.Flux<TopicPermissions> getTopicPermissions()
      • clearTopicPermissions

        public reactor.core.publisher.Mono<HttpResponse> clearTopicPermissions​(String vhost,
                                                                               String username)
      • getExchanges

        public reactor.core.publisher.Flux<ExchangeInfo> getExchanges()
      • getExchanges

        public reactor.core.publisher.Flux<ExchangeInfo> getExchanges​(String vhost)
      • publish

        public reactor.core.publisher.Mono<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
      • getClusterName

        public reactor.core.publisher.Mono<ClusterId> getClusterName()
      • setClusterName

        public reactor.core.publisher.Mono<HttpResponse> setClusterName​(String name)
      • getExtensions

        public reactor.core.publisher.Flux<Map> getExtensions()
      • getDefinitions

        public reactor.core.publisher.Mono<Definitions> getDefinitions()
      • getQueues

        public reactor.core.publisher.Flux<QueueInfo> getQueues()
      • getQueues

        public reactor.core.publisher.Flux<QueueInfo> getQueues​(String vhost)
      • get

        public reactor.core.publisher.Flux<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 messages wrapped in a Flux
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • get

        public reactor.core.publisher.Flux<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 messages wrapped in a Flux
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • get

        public reactor.core.publisher.Mono<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 wrapped in a Mono
        Since:
        3.4.0
        See Also:
        GetAckMode, GetEncoding
      • getBindings

        public reactor.core.publisher.Flux<BindingInfo> getBindings()
      • getBindings

        public reactor.core.publisher.Flux<BindingInfo> getBindings​(String vhost)
      • getExchangeBindingsBySource

        public reactor.core.publisher.Flux<BindingInfo> getExchangeBindingsBySource​(String vhost,
                                                                                    String exchange)
      • getExchangeBindingsByDestination

        public reactor.core.publisher.Flux<BindingInfo> getExchangeBindingsByDestination​(String vhost,
                                                                                         String exchange)
      • getQueueBindings

        public reactor.core.publisher.Flux<BindingInfo> getQueueBindings​(String vhost,
                                                                         String queue)
      • getQueueBindingsBetween

        public reactor.core.publisher.Flux<BindingInfo> getQueueBindingsBetween​(String vhost,
                                                                                String exchange,
                                                                                String queue)
      • getExchangeBindingsBetween

        public reactor.core.publisher.Flux<BindingInfo> getExchangeBindingsBetween​(String vhost,
                                                                                   String source,
                                                                                   String destination)
      • getShovels

        public reactor.core.publisher.Flux<ShovelInfo> getShovels()
      • getShovelsStatus

        public reactor.core.publisher.Flux<ShovelStatus> getShovelsStatus()
      • declareUpstream

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
      • deleteUpstream

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
      • getUpstreams

        public reactor.core.publisher.Flux<UpstreamInfo> getUpstreams()
        Returns a list of upstreams for "/" virtual host
        Returns:
        flux of upstream info
      • getUpstreams

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

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
      • deleteUpstreamSet

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
      • getUpstreamSets

        public reactor.core.publisher.Flux<UpstreamSetInfo> getUpstreamSets()
        Returns a list of upstream sets for "/" virtual host
        Returns:
        flux of upstream set info
      • getUpstreamSets

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

        public reactor.core.publisher.Flux<VhostLimits> getVhostLimits()
        Returns the limits (max queues and connections) for all virtual hosts.
        Returns:
        flux of the limits
        Since:
        3.7.0
      • getVhostLimits

        public reactor.core.publisher.Mono<VhostLimits> getVhostLimits​(String vhost)
        Returns the limits (max queues and connections) for a given virtual host.
        Parameters:
        vhost - the virtual host
        Returns:
        flux of the limits for this virtual host
        Since:
        3.7.0
      • limitMaxNumberOfConnections

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
        Since:
        3.7.0
      • limitMaxNumberOfQueues

        public reactor.core.publisher.Mono<HttpResponse> 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
        Returns:
        HTTP response in a mono
        Since:
        3.7.0
      • clearMaxConnectionsLimit

        public reactor.core.publisher.Mono<HttpResponse> clearMaxConnectionsLimit​(String vhost)
        Clears the connection limit for a virtual host.
        Parameters:
        vhost - the virtual host
        Returns:
        HTTP response in a mono
        Since:
        3.7.0
      • clearMaxQueuesLimit

        public reactor.core.publisher.Mono<HttpResponse> clearMaxQueuesLimit​(String vhost)
        Clears the queue limit for a virtual host.
        Parameters:
        vhost - the virtual host
        Returns:
        HTTP response in a mono
        Since:
        3.7.0
      • decode

        protected <T> BiFunction<? super reactor.netty.http.client.HttpClientResponse,​? super reactor.netty.ByteBufFlux,​org.reactivestreams.Publisher<T>> decode​(Class<T> type)
      • authorizedHeader

        protected Function<? super io.netty.handler.codec.http.HttpHeaders,​reactor.core.publisher.Mono<? extends io.netty.handler.codec.http.HttpHeaders>> authorizedHeader()
      • applyResponseCallback

        protected Consumer<reactor.netty.http.client.HttpClientResponse> applyResponseCallback()