Class StreamEnvironmentBuilder
- All Implemented Interfaces:
EnvironmentBuilder
-
Nested Class Summary
Nested classes/interfaces inherited from interface EnvironmentBuilder
EnvironmentBuilder.NettyConfiguration, EnvironmentBuilder.OAuth2Configuration, EnvironmentBuilder.TlsConfiguration -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddressResolver(AddressResolver addressResolver) AnAddressResolverto potentially change resolved node address to connect to.build()Create theEnvironmentinstance.chunkChecksum(ChunkChecksum chunkChecksum) The checksum strategy used for chunk checksum.clientProperties(Map<String, String> clientProperties) Custom client properties to add to default client properties.clientProperty(String key, String value) Add a custom client properties to default client properties.The AMQP 1.0 codec used to encode and decode AMQP 1.0 messages.compressionCodecFactory(CompressionCodecFactory compressionCodecFactory) Compression codec factory to use for compression in sub-entry batching.credentialsProvider(CredentialsProvider credentialsProvider) TheCredentialsProviderto use.forceLeaderForProducers(boolean forceLeader) Flag to force the connection to the stream leader for producers.forceReplicaForConsumers(boolean forceReplica) Flag to force the connection to a stream replica for consumers.The host to connect to.Informational ID for this environment instance.lazyInitialization(boolean lazy) To delay the connection opening until necessary.locatorConnectionCount(int locatorCount) Set the expected number of "locator" connections to maintain.maxConsumersByConnection(int maxConsumersByConnection) The maximum number of consumers allocated to a single connection.maxProducersByConnection(int maxProducersByConnection) The maximum number of producers allocated to a single connection.maxTrackingConsumersByConnection(int maxTrackingConsumersByConnection) The maximum number of tracking consumers allocated to a single connection.metricsCollector(MetricsCollector metricsCollector) Set up aMetricsCollector.netty()Helper to configure netty.oauth2()OAuth 2 settings.observationCollector(ObservationCollector<?> observationCollector) Set up anObservationCollector.The password to use.port(int port) The port to use to connect.recoveryBackOffDelayPolicy(BackOffDelayPolicy recoveryBackOffDelayPolicy) TheBackOffDelayPolicyto use for connection recovery.requestedHeartbeat(Duration requestedHeartbeat) The heartbeat to request.requestedMaxFrameSize(int requestedMaxFrameSize) The maximum frame size to request.rpcTimeout(Duration timeout) Timeout for RPC calls.saslConfiguration(SaslConfiguration saslConfiguration) The SASL configuration to use.scheduledExecutorService(ScheduledExecutorService scheduledExecutorService) Set theScheduledExecutorServiceused to: Schedule producers batch sending Handle connection recovery Handle topology updatetls()Enable and configure TLS.topologyUpdateBackOffDelayPolicy(BackOffDelayPolicy topologyUpdateBackOffDelayPolicy) TheBackOffDelayPolicyto use for topology recovery.The URI of a node to connect to.A list of URIs of nodes of the same cluster to use to connect to.The username to use.virtualHost(String virtualHost) The virtual host to connect to.
-
Constructor Details
-
StreamEnvironmentBuilder
public StreamEnvironmentBuilder()
-
-
Method Details
-
uri
Description copied from interface:EnvironmentBuilderThe URI of a node to connect to.URI must be of the form
rabbitmq-stream://guest:guest@localhost:5552/%2f.- Specified by:
uriin interfaceEnvironmentBuilder- Parameters:
uriString-- Returns:
- this builder instance
-
uris
Description copied from interface:EnvironmentBuilderA list of URIs of nodes of the same cluster to use to connect to.URIs must be of the form
rabbitmq-stream://guest:guest@localhost:5552/%2f.- Specified by:
urisin interfaceEnvironmentBuilder- Parameters:
uris-- Returns:
- this builder instance
-
host
Description copied from interface:EnvironmentBuilderThe host to connect to.- Specified by:
hostin interfaceEnvironmentBuilder- Parameters:
host-- Returns:
- this builder instance
-
port
Description copied from interface:EnvironmentBuilderThe port to use to connect.- Specified by:
portin interfaceEnvironmentBuilder- Parameters:
port-- Returns:
- this builder instance
-
codec
Description copied from interface:EnvironmentBuilderThe AMQP 1.0 codec used to encode and decode AMQP 1.0 messages.- Specified by:
codecin interfaceEnvironmentBuilder- Parameters:
codec-- Returns:
- this builder instance
-
compressionCodecFactory
Description copied from interface:EnvironmentBuilderCompression codec factory to use for compression in sub-entry batching.- Specified by:
compressionCodecFactoryin interfaceEnvironmentBuilder- Parameters:
compressionCodecFactory-- Returns:
- this builder instance
- See Also:
-
id
Description copied from interface:EnvironmentBuilderInformational ID for this environment instance.This is currently used as a prefix for connection names. The broker does not enforce any kind of uniqueness based on this property. Default to
rabbitmq-stream.- Specified by:
idin interfaceEnvironmentBuilder- Parameters:
id-- Returns:
- this builder instance
-
rpcTimeout
Description copied from interface:EnvironmentBuilderTimeout for RPC calls.Default is 10 seconds.
- Specified by:
rpcTimeoutin interfaceEnvironmentBuilder- Parameters:
timeout-- Returns:
- this builder instance
-
saslConfiguration
Description copied from interface:EnvironmentBuilderThe SASL configuration to use.- Specified by:
saslConfigurationin interfaceEnvironmentBuilder- Parameters:
saslConfiguration-- Returns:
- this builder instance
- See Also:
-
credentialsProvider
Description copied from interface:EnvironmentBuilderTheCredentialsProviderto use.- Specified by:
credentialsProviderin interfaceEnvironmentBuilder- Parameters:
credentialsProvider-- Returns:
- this builder instance
- See Also:
-
username
Description copied from interface:EnvironmentBuilderThe username to use.- Specified by:
usernamein interfaceEnvironmentBuilder- Parameters:
username-- Returns:
- this builder instance
-
password
Description copied from interface:EnvironmentBuilderThe password to use.- Specified by:
passwordin interfaceEnvironmentBuilder- Parameters:
password-- Returns:
- this builder instance
-
virtualHost
Description copied from interface:EnvironmentBuilderThe virtual host to connect to.- Specified by:
virtualHostin interfaceEnvironmentBuilder- Parameters:
virtualHost-- Returns:
- this builder instance
-
requestedHeartbeat
Description copied from interface:EnvironmentBuilderThe heartbeat to request.Default is 60 seconds.
- Specified by:
requestedHeartbeatin interfaceEnvironmentBuilder- Parameters:
requestedHeartbeat-- Returns:
- this builder instance
- See Also:
-
requestedMaxFrameSize
Description copied from interface:EnvironmentBuilderThe maximum frame size to request.Default is 1048576.
- Specified by:
requestedMaxFrameSizein interfaceEnvironmentBuilder- Parameters:
requestedMaxFrameSize-- Returns:
- this builder instance
- See Also:
-
chunkChecksum
Description copied from interface:EnvironmentBuilderThe checksum strategy used for chunk checksum.The default is CRC32 based on JDK implementation.
- Specified by:
chunkChecksumin interfaceEnvironmentBuilder- Parameters:
chunkChecksum-- Returns:
- this builder instance
-
clientProperties
Description copied from interface:EnvironmentBuilderCustom client properties to add to default client properties.- Specified by:
clientPropertiesin interfaceEnvironmentBuilder- Parameters:
clientProperties-- Returns:
- this builder instance
-
clientProperty
Description copied from interface:EnvironmentBuilderAdd a custom client properties to default client properties.- Specified by:
clientPropertyin interfaceEnvironmentBuilder- Parameters:
key-value-- Returns:
- this builder instance
-
metricsCollector
Description copied from interface:EnvironmentBuilderSet up aMetricsCollector.- Specified by:
metricsCollectorin interfaceEnvironmentBuilder- Parameters:
metricsCollector-- Returns:
- this builder instance
-
scheduledExecutorService
public EnvironmentBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService) Description copied from interface:EnvironmentBuilderSet theScheduledExecutorServiceused to:- Schedule producers batch sending
- Handle connection recovery
- Handle topology update
- Specified by:
scheduledExecutorServicein interfaceEnvironmentBuilder- Parameters:
scheduledExecutorService- the service to use- Returns:
- this builder instance
-
recoveryBackOffDelayPolicy
Description copied from interface:EnvironmentBuilderTheBackOffDelayPolicyto use for connection recovery.The default is a fixed delay of 5 seconds.
- Specified by:
recoveryBackOffDelayPolicyin interfaceEnvironmentBuilder- Parameters:
recoveryBackOffDelayPolicy-- Returns:
- this builder instance
-
topologyUpdateBackOffDelayPolicy
public EnvironmentBuilder topologyUpdateBackOffDelayPolicy(BackOffDelayPolicy topologyUpdateBackOffDelayPolicy) Description copied from interface:EnvironmentBuilderTheBackOffDelayPolicyto use for topology recovery.Topology recovery can kick in when streams leaders and replicas move from nodes to nodes in the cluster.
The default is a first delay of 5 seconds, then 1 second for the next attempts.
- Specified by:
topologyUpdateBackOffDelayPolicyin interfaceEnvironmentBuilder- Parameters:
topologyUpdateBackOffDelayPolicy-- Returns:
- this builder instance
-
addressResolver
Description copied from interface:EnvironmentBuilderAnAddressResolverto potentially change resolved node address to connect to.Applications can use this abstraction to make sure connection attempts ignore metadata hints and always go to a single point like a load balancer. Consider setting
EnvironmentBuilder.locatorConnectionCount(int)when using a load balancer.The default implementation does not perform any logic, it just returns the passed-in address.
The default implementation is overridden automatically if the following conditions are met: the host to connect to is
localhost, the user isguest, and no address resolver has been provided. The client will then always try to connect tolocalhostto facilitate local development. Just provide a pass-through address resolver to avoid this behavior, e.g.:Environment.builder() .addressResolver(address -> address) .build();
- Specified by:
addressResolverin interfaceEnvironmentBuilder- Parameters:
addressResolver- the address resolver- Returns:
- this builder instance
- See Also:
-
maxProducersByConnection
Description copied from interface:EnvironmentBuilderThe maximum number of producers allocated to a single connection.Default is 256, which is the maximum value.
The limit may not be strictly enforced in case of too many concurrent creations.
- Specified by:
maxProducersByConnectionin interfaceEnvironmentBuilder- Parameters:
maxProducersByConnection-- Returns:
- this builder instance
-
maxTrackingConsumersByConnection
Description copied from interface:EnvironmentBuilderThe maximum number of tracking consumers allocated to a single connection.Default is 50, which is the maximum value.
The limit may not be strictly enforced in case of too many concurrent creations.
- Specified by:
maxTrackingConsumersByConnectionin interfaceEnvironmentBuilder- Parameters:
maxTrackingConsumersByConnection-- Returns:
- this builder instance
-
maxConsumersByConnection
Description copied from interface:EnvironmentBuilderThe maximum number of consumers allocated to a single connection.Default is 256, which is the maximum value.
The limit may not be strictly enforced in case of too many concurrent creations.
- Specified by:
maxConsumersByConnectionin interfaceEnvironmentBuilder- Parameters:
maxConsumersByConnection-- Returns:
- this builder instance
-
lazyInitialization
Description copied from interface:EnvironmentBuilderTo delay the connection opening until necessary.No connection will be open before it is necessary (for stream management or producer/consumer creation).
Default is false.
- Specified by:
lazyInitializationin interfaceEnvironmentBuilder- Parameters:
lazy-- Returns:
- this builder instance
-
forceReplicaForConsumers
Description copied from interface:EnvironmentBuilderFlag to force the connection to a stream replica for consumers.The library will always prefer to connect to a stream replica to consume from, but it will fall back to the stream leader if no replica is available. This is the default behavior. Set this flag to
trueto make the library wait for a replica to become available if only the stream leader is available. This can lead to longer recovery time but help to offload a stream leader and let it deal only with write requests.Note the library performs only 5 attempts to locate a replica before falling back to the leader when the flag is set to
true.The
EnvironmentBuilder.recoveryBackOffDelayPolicy(BackOffDelayPolicy)andEnvironmentBuilder.topologyUpdateBackOffDelayPolicy(BackOffDelayPolicy)policies control the time between attempts.Do not set this flag to
truewhen streams have only 1 member (the leader), e.g. for local development.Default is
false.- Specified by:
forceReplicaForConsumersin interfaceEnvironmentBuilder- Parameters:
forceReplica- whether to force the connection to a replica or not- Returns:
- this builder instance
- See Also:
-
forceLeaderForProducers
Description copied from interface:EnvironmentBuilderFlag to force the connection to the stream leader for producers.The library prefers to connect to a node that hosts a stream leader for producers (default behavior).
When using a load balancer, the library does not know in advance the node it connects to. It may have to retry to connect to the appropriate node.
It will retry until it connects to the appropriate node (flag set to
true, the default). This provides the best data locality, but may require several attempts, delaying the creation or the recovery of producers. This usually suits high-throughput use cases.The library will accept the connection to a stream replica if the flag is set to
false. This will speed up the creation/recovery of producers, but at the cost of network hops between cluster nodes when publishing messages because only a stream leader accepts writes. This is usually acceptable for low-throughput use cases.Changing the default value should only benefit systems where a load balancer sits between the client applications and the cluster nodes.
Default is
true.- Specified by:
forceLeaderForProducersin interfaceEnvironmentBuilder- Parameters:
forceLeader- whether to force the connection to the leader or not- Returns:
- this builder instance
- See Also:
-
tls
Description copied from interface:EnvironmentBuilderEnable and configure TLS.- Specified by:
tlsin interfaceEnvironmentBuilder- Returns:
- the TLS configuration helper
-
netty
Description copied from interface:EnvironmentBuilderHelper to configure netty.- Specified by:
nettyin interfaceEnvironmentBuilder- Returns:
- Netty configuration helper
-
oauth2
Description copied from interface:EnvironmentBuilderOAuth 2 settings.- Specified by:
oauth2in interfaceEnvironmentBuilder- Returns:
- OAuth 2 settings
- See Also:
-
observationCollector
Description copied from interface:EnvironmentBuilderSet up anObservationCollector.- Specified by:
observationCollectorin interfaceEnvironmentBuilder- Parameters:
observationCollector-- Returns:
- this builder instance
-
locatorConnectionCount
Description copied from interface:EnvironmentBuilderSet the expected number of "locator" connections to maintain.Locator connections are used to perform infrastructure-related operations (e.g. looking up the topology of a stream to find an appropriate node to connect to).
It is recommended to maintain 2 to 3 locator connections. The environment uses the smaller of the number of passed-in URIs and 3 by default (see
EnvironmentBuilder.uris(List)).The number of locator connections should be explicitly set when a load balancer is used, as the environment cannot know the number of cluster nodes in this case (the only URI set is the one of the load balancer).
- Specified by:
locatorConnectionCountin interfaceEnvironmentBuilder- Parameters:
locatorCount- number of expected locator connections- Returns:
- this builder instance
- See Also:
-
build
Description copied from interface:EnvironmentBuilderCreate theEnvironmentinstance.- Specified by:
buildin interfaceEnvironmentBuilder- Returns:
- the configured environment
-