Class ReactiveCluster


  • public class ReactiveCluster
    extends Object
    The Cluster is the main entry point when connecting to a Couchbase cluster using the reactive APIs.

    Most likely you want to start out by using the connect(String, String, String) entry point. For more advanced options you want to use the connect(String, ClusterOptions) method. The entry point that allows overriding the seed nodes (connect(Set, ClusterOptions) is only needed if you run a couchbase cluster at non-standard ports.

    When the application shuts down (or the SDK is not needed anymore), you are required to call disconnect(). If you omit this step, the application will terminate (all spawned threads are daemon threads) but any operations or work in-flight will not be able to complete and lead to undesired side-effects. Note that disconnect will also shutdown all associated buckets.

    Cluster-level operations like query(String) will not work unless at leas one bucket is opened against a pre 6.5 cluster. If you are using 6.5 or later, you can run cluster-level queries without opening a bucket. All of these operations are lazy, so the SDK will bootstrap in the background and service queries as quickly as possible. This also means that the first operations might be a bit slower until all sockets are opened in the background and the configuration is loaded. If you want to wait explicitly, you can utilize the waitUntilReady(Duration) method before performing your first query.

    The SDK will only work against Couchbase Server 5.0 and later, because RBAC (role-based access control) is a first class concept since 3.0 and therefore required.

    • Method Detail

      • connect

        public static ReactiveCluster connect​(String connectionString,
                                              String username,
                                              String password)
        Connect to a Couchbase cluster with a username and a password as credentials.
        Parameters:
        connectionString - connection string used to locate the Couchbase cluster.
        username - the name of the user with appropriate permissions on the cluster.
        password - the password of the user with appropriate permissions on the cluster.
        Returns:
        the instantiated ReactiveCluster.
      • connect

        public static ReactiveCluster connect​(String connectionString,
                                              ClusterOptions options)
        Connect to a Couchbase cluster with custom Authenticator.
        Parameters:
        connectionString - connection string used to locate the Couchbase cluster.
        options - custom options when creating the cluster.
        Returns:
        the instantiated ReactiveCluster.
      • connect

        public static ReactiveCluster connect​(Set<SeedNode> seedNodes,
                                              ClusterOptions options)
        Connect to a Couchbase cluster with a list of seed nodes and custom options.

        Please note that you likely only want to use this method if you need to pass in custom ports for specific seed nodes during bootstrap. Otherwise we recommend relying ont he simpler connect(String, ClusterOptions) method instead.

        Parameters:
        seedNodes - the seed nodes used to connect to the cluster.
        options - custom options when creating the cluster.
        Returns:
        the instantiated ReactiveCluster.
      • core

        @Volatile
        public Core core()
        Provides access to the underlying Core.

        This is advanced API, use with care!

      • disconnect

        public Mono<Void> disconnect()
        Performs a non-reversible disconnect of this ReactiveCluster.

        If this method is used, the default disconnect timeout on the environment is used. Please use the companion overload (disconnect(Duration) if you want to provide a custom duration.

        If a custom ClusterEnvironment has been passed in during connect, it is VERY important to shut it down after calling this method. This will prevent any in-flight tasks to be stopped prematurely.

      • disconnect

        public Mono<Void> disconnect​(Duration timeout)
        Performs a non-reversible disconnect of this ReactiveCluster.

        If a custom ClusterEnvironment has been passed in during connect, it is VERY important to shut it down after calling this method. This will prevent any in-flight tasks to be stopped prematurely.

        Parameters:
        timeout - overriding the default disconnect timeout if needed.
      • diagnostics

        public Mono<DiagnosticsResult> diagnostics()
        Runs a diagnostic report on the current state of the cluster from the SDKs point of view.

        Please note that it does not perform any I/O to do this, it will only use the current known state of the cluster to assemble the report (so, if for example no N1QL query has been run the socket pool might be empty and as result not show up in the report).

        Returns:
        the DiagnosticsResult once complete.
      • diagnostics

        public Mono<DiagnosticsResult> diagnostics​(DiagnosticsOptions options)
        Runs a diagnostic report with custom options on the current state of the cluster from the SDKs point of view.

        Please note that it does not perform any I/O to do this, it will only use the current known state of the cluster to assemble the report (so, if for example no N1QL query has been run the socket pool might be empty and as result not show up in the report).

        Parameters:
        options - options that allow to customize the report.
        Returns:
        the DiagnosticsResult once complete.
      • ping

        public Mono<PingResult> ping()
        Performs application-level ping requests against services in the couchbase cluster.

        Note that this operation performs active I/O against services and endpoints to assess their health. If you do not wish to perform I/O, consider using the diagnostics() instead. You can also combine the functionality of both APIs as needed, which is waitUntilReady(Duration) is doing in its implementation as well.

        Returns:
        the PingResult once complete.
      • ping

        public Mono<PingResult> ping​(PingOptions options)
        Performs application-level ping requests with custom options against services in the couchbase cluster.

        Note that this operation performs active I/O against services and endpoints to assess their health. If you do not wish to perform I/O, consider using the diagnostics(DiagnosticsOptions) instead. You can also combine the functionality of both APIs as needed, which is waitUntilReady(Duration) is doing in its implementation as well.

        Returns:
        the PingResult once complete.
      • waitUntilReady

        public Mono<Void> waitUntilReady​(Duration timeout)
        Waits until the desired ClusterState is reached.

        This method will wait until either the cluster state is "online", or the timeout is reached. Since the SDK is bootstrapping lazily, this method allows to eagerly check during bootstrap if all of the services are online and usable before moving on.

        Parameters:
        timeout - the maximum time to wait until readiness.
        Returns:
        a mono that completes either once ready or timeout.
      • waitUntilReady

        public Mono<Void> waitUntilReady​(Duration timeout,
                                         WaitUntilReadyOptions options)
        Waits until the desired ClusterState is reached.

        This method will wait until either the cluster state is "online" by default, or the timeout is reached. Since the SDK is bootstrapping lazily, this method allows to eagerly check during bootstrap if all of the services are online and usable before moving on. You can tune the properties through WaitUntilReadyOptions.

        Parameters:
        timeout - the maximum time to wait until readiness.
        options - the options to customize the readiness waiting.
        Returns:
        a mono that completes either once ready or timeout.