Class AxonServerConnectionFactory.Builder

    • Constructor Detail

      • Builder

        protected Builder​(String componentName,
                          String clientInstanceId)
        Initializes a builder with the mandatory parameters: the componentName and clientInstanceId.
        Parameters:
        componentName - The name of the component connecting to AxonServer
        clientInstanceId - The unique instance identifier for this instance of the component
    • Method Detail

      • routingServers

        public AxonServerConnectionFactory.Builder routingServers​(ServerAddress... serverAddresses)
        Provides the addresses of the AxonServer instances used to set up the initial connection. Ideally, these are all the known admin nodes of the AxonServer Cluster to connect with.

        The addresses are tried in the order provided, until one send a successful reply.

        Defaults to "localhost:8024".

        Parameters:
        serverAddresses - The addresses to try to set up the initial connection with.
        Returns:
        this builder for further configuration
      • reconnectInterval

        public AxonServerConnectionFactory.Builder reconnectInterval​(long interval,
                                                                     TimeUnit timeUnit)
        Sets the amount of time to wait in between attempts to connect to AxonServer. A single attempt involves connecting to each of the configured routing Servers (see routingServers(ServerAddress...)).

        Defaults to 2 seconds.

        Parameters:
        interval - The amount of time to wait in between connection attempts
        timeUnit - The unit in which the interval is expressed
        Returns:
        this builder for further configuration
      • connectTimeout

        public AxonServerConnectionFactory.Builder connectTimeout​(long timeout,
                                                                  TimeUnit timeUnit)
        Sets the timeout within which a connection has to be established with an AxonServer instance.

        Defaults to 10 seconds.

        Parameters:
        timeout - The amount of time to wait for a connection to be established
        timeUnit - The unit in which the timout is expressed
        Returns:
        this builder for further configuration
      • clientTags

        public AxonServerConnectionFactory.Builder clientTags​(Map<String,​String> additionalClientTags)
        Configures the given additionalClientTags which describe this client. Any existing tags with the same key as any of the additional tags provided, will be overwritten.

        Tags are used to locate the best matching AxonServer instance to connect with. The instance with the most matching Tags (both key and value must be equal) will be selected.

        By default, no tags are defined.

        Parameters:
        additionalClientTags - additional tags that define this client component
        Returns:
        this builder for further configuration
      • clientTag

        public AxonServerConnectionFactory.Builder clientTag​(String key,
                                                             String value)
        Configures an additional Tag with given key and value which describes this client. Any existing tags with the same key will be overwritten.

        Tags are used to locate the best matching AxonServer instance to connect with. The instance with the most matching Tags (both key and value must be equal) will be selected.

        By default, no tags are defined.

        Parameters:
        key - the key of the Tag to configure
        value - the value of the Tag to configure
        Returns:
        this builder for further configuration
      • token

        public AxonServerConnectionFactory.Builder token​(String token)
        Defines the token used to authorize activity from this component on AxonServer.

        Defaults to not using a Token. Defining a Token is mandatory when token-based authentication is enabled on AxonServer.

        Parameters:
        token - The token to which the required authorizations have been assigned.
        Returns:
        this builder for further configuration
      • useTransportSecurity

        public AxonServerConnectionFactory.Builder useTransportSecurity​(io.grpc.netty.shaded.io.netty.handler.ssl.SslContext sslContext)
        Configures the use of Transport Layer Security (TLS) using the settings from the given sslContext.

        Defaults to not using TLS.

        Parameters:
        sslContext - The context defining TLS parameters
        Returns:
        this builder for further configuration
        See Also:
        SslContextBuilder.forClient()
      • forceReconnectViaRoutingServers

        public AxonServerConnectionFactory.Builder forceReconnectViaRoutingServers​(boolean forceReconnectViaRoutingServers)
        Indicates whether the connector should always reconnect via the Routing Servers. When true (default), the connector will contact the Routing Servers for a new destination each time a connection is dropped. When false, the connector will first attempt to re-establish a connection to the node is was previously connected to. When that fails, only then will it contact the Routing Servers.

        Default to true, forcing the failed connection to be abandoned and a new one to be requested via the routing servers.

        Parameters:
        forceReconnectViaRoutingServers - whether to force a reconnect to the Cluster via the RoutingServers.
        Returns:
        this builder for further configuration
      • threadPoolSize

        public AxonServerConnectionFactory.Builder threadPoolSize​(int poolSize)
        Defines the number of Threads that should be used for Connection Management activities by this connector. This includes activities related to connecting to AxonServer, setting up instruction streams, sending and validating heartbeats, etc.

        Defaults to 2.

        Parameters:
        poolSize - The number of threads to assign to Connection related activities.
        Returns:
        this builder for further configuration
      • usingKeepAlive

        public AxonServerConnectionFactory.Builder usingKeepAlive​(long interval,
                                                                  long timeout,
                                                                  TimeUnit timeUnit,
                                                                  boolean keepAliveWithoutCalls)
        Sets the time without read activity before sending a keepalive ping. An unreasonably small value might be increased, and Long.MAX_VALUE nano seconds or an unreasonably large value will disable keepalive. Defaults to infinite.

        If no read activity is recorded within the given timeout after sending a keepalive ping, the connection is considered dead.

        Clients must receive permission from the service owner before enabling this option. Keepalives can increase the load on services and are commonly "invisible" making it hard to notice when they are causing excessive load. Clients are strongly encouraged to use only as small of a value as necessary.

        Parameters:
        interval - time without read activity before sending a keepalive ping
        timeout - the time waiting for read activity after sending a keepalive ping
        timeUnit - the unit in which the interval and timeout are expressed
        Returns:
        this builder for further configuration
      • maxInboundMessageSize

        public AxonServerConnectionFactory.Builder maxInboundMessageSize​(int bytes)
        Sets the maximum size for inbound messages. Requests receiving messages larger than the threshold will be cancelled.

        Default to 4 MiB.

        Parameters:
        bytes - The number of bytes to limit inbound message to
        Returns:
        this builder for further configuration
      • customize

        public AxonServerConnectionFactory.Builder customize​(UnaryOperator<io.grpc.ManagedChannelBuilder<?>> customization)
        Registers the given customization, which configures the underling ManagedChannelBuilder used to set up connections to AxonServer.

        This method may be used in case none of the operations on this Builder provide support for the required feature.

        Parameters:
        customization - A function defining the customization to make on the ManagedChannelBuilder
        Returns:
        this builder for further configuration
      • processorInfoUpdateFrequency

        public AxonServerConnectionFactory.Builder processorInfoUpdateFrequency​(long interval,
                                                                                TimeUnit unit)
        Sets the frequency in which the status of all Event Processors is emitted to the Server. Defaults to 2 seconds.
        Parameters:
        interval - The interval in which to send status updates
        unit - The unit of time in which the interval is expressed
        Returns:
        this builder for further configuration
      • queryPermits

        public AxonServerConnectionFactory.Builder queryPermits​(int permits)
        Sets the number of messages that a Query Handler may receive before any of them have been processed. Defaults to 5000.

        Values lower than 16 will be replaced with 16.

        Parameters:
        permits - The number of initial permits
        Returns:
        this builder for further configuration
      • commandPermits

        public AxonServerConnectionFactory.Builder commandPermits​(int permits)
        Sets the number of messages that a Command Handler may receive before any of them have been processed. Defaults to 5000.

        Values lower than 16 will be replaced with 16.

        Parameters:
        permits - The number of initial permits
        Returns:
        this builder for further configuration
      • validate

        protected void validate()
        Validates the state of the builder, setting defaults where necessary.

        This method is protected to allow overriding by subclasses. Subclasses are recommended to call this method as part of their own validation process.