Class AxonServerConnectionFactory.Builder
- java.lang.Object
-
- io.axoniq.axonserver.connector.AxonServerConnectionFactory.Builder
-
- Enclosing class:
- AxonServerConnectionFactory
public static class AxonServerConnectionFactory.Builder extends Object
Builder for AxonServerConnectionFactory instances. The methods on this class allow for configuration of theAxonServerConnectionFactoryinstance used to connect to an AxonServer (cluster).This class is not intended to be instantiated directly, but rather through
AxonServerConnectionFactory.forClient(String)orAxonServerConnectionFactory.forClient(String, String).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AxonServerConnectionFactorybuild()Builds anAxonServerConnectionFactoryusing the setting defined in this builder instance.AxonServerConnectionFactory.BuilderclientTag(String key, String value)Configures an additional Tag with givenkeyandvaluewhich describes this client.AxonServerConnectionFactory.BuilderclientTags(Map<String,String> additionalClientTags)Configures the givenadditionalClientTagswhich describe this client.AxonServerConnectionFactory.BuildercommandPermits(int permits)Sets the number of messages that a Command Handler may receive before any of them have been processed.AxonServerConnectionFactory.BuilderconnectTimeout(long timeout, TimeUnit timeUnit)Sets the timeout within which a connection has to be established with an AxonServer instance.AxonServerConnectionFactory.Buildercustomize(UnaryOperator<io.grpc.ManagedChannelBuilder<?>> customization)Registers the givencustomization, which configures the underlingManagedChannelBuilderused to set up connections to AxonServer.AxonServerConnectionFactory.BuilderforceReconnectViaRoutingServers(boolean forceReconnectViaRoutingServers)Indicates whether the connector should always reconnect via the Routing Servers.AxonServerConnectionFactory.BuildermaxInboundMessageSize(int bytes)Sets the maximum size for inbound messages.AxonServerConnectionFactory.BuilderprocessorInfoUpdateFrequency(long interval, TimeUnit unit)Sets the frequency in which the status of all Event Processors is emitted to the Server.AxonServerConnectionFactory.BuilderqueryPermits(int permits)Sets the number of messages that a Query Handler may receive before any of them have been processed.AxonServerConnectionFactory.BuilderreconnectInterval(long interval, TimeUnit timeUnit)Sets the amount of time to wait in between attempts to connect to AxonServer.AxonServerConnectionFactory.BuilderroutingServers(ServerAddress... serverAddresses)Provides the addresses of the AxonServer instances used to set up the initial connection.AxonServerConnectionFactory.BuilderthreadPoolSize(int poolSize)Defines the number of Threads that should be used for Connection Management activities by this connector.AxonServerConnectionFactory.Buildertoken(String token)Defines the token used to authorize activity from this component on AxonServer.AxonServerConnectionFactory.BuilderuseTransportSecurity()Configures the use of Transport Layer Security (TLS) using the default settings from the JVM.AxonServerConnectionFactory.BuilderuseTransportSecurity(io.grpc.netty.shaded.io.netty.handler.ssl.SslContext sslContext)Configures the use of Transport Layer Security (TLS) using the settings from the givensslContext.AxonServerConnectionFactory.BuilderusingKeepAlive(long interval, long timeout, TimeUnit timeUnit, boolean keepAliveWithoutCalls)Sets the time without read activity before sending a keepalive ping.protected voidvalidate()Validates the state of the builder, setting defaults where necessary.
-
-
-
Constructor Detail
-
Builder
protected Builder(String componentName, String clientInstanceId)
Initializes a builder with the mandatory parameters: thecomponentNameandclientInstanceId.- Parameters:
componentName- The name of the component connecting to AxonServerclientInstanceId- 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 (seeroutingServers(ServerAddress...)).Defaults to 2 seconds.
- Parameters:
interval- The amount of time to wait in between connection attemptstimeUnit- 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 establishedtimeUnit- 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 givenadditionalClientTagswhich 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 givenkeyandvaluewhich 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 configurevalue- 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()
Configures the use of Transport Layer Security (TLS) using the default settings from the JVM.Defaults to not using TLS.
- Returns:
- this builder for further configuration
- See Also:
useTransportSecurity(SslContext)
-
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 givensslContext.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. Whentrue(default), the connector will contact the Routing Servers for a new destination each time a connection is dropped. Whenfalse, 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 pingtimeout- the time waiting for read activity after sending a keepalive pingtimeUnit- 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 givencustomization, which configures the underlingManagedChannelBuilderused 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 updatesunit- 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.
-
build
public AxonServerConnectionFactory build()
Builds anAxonServerConnectionFactoryusing the setting defined in this builder instance.- Returns:
- a fully configured AxonServerConnectionFactory, ready to set up connections to AxonServer
-
-