Class BrokerAssociatedNameStrategy
java.lang.Object
io.confluent.kafka.serializers.subject.AssociatedNameStrategy
io.confluent.kafka.schemaregistry.validator.BrokerAssociatedNameStrategy
- All Implemented Interfaces:
io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy, org.apache.kafka.common.Configurable
public class BrokerAssociatedNameStrategy
extends io.confluent.kafka.serializers.subject.AssociatedNameStrategy
A broker-side
AssociatedNameStrategy that replaces the parent's synchronous Guava cache
with a Caffeine cache tuned for broker schema validation. Compared to the parent it:
- Refreshes instead of expiring on the hot path. Associations are mutable, so a
resolved subject is refreshed in the background (
refreshAfterWrite) rather than evicted. After the one-time cold load, reads never block on a synchronous Schema Registry call: an entry past the refresh interval is refreshed asynchronously while its existing value keeps being served, and a failed refresh retains that value. Refresh is best-effort — correctness never depends on it keeping up. The parent'sexpireAfterWriteinstead forced a synchronous Schema Registry call on the append thread at every TTL boundary. - Serves stale during outages (availability). While Schema Registry is unreachable, refreshes fail and the last-known association keeps being served indefinitely rather than blocking or rejecting; the next successful async refresh restores freshness.
- Retries only transient failures.
IOExceptionand5xxresponses are retried (reusing the validator's retry knobs); a4xxis a definitive transport error and is surfaced immediately. A legitimate answer — no association (empty list / 404 endpoint), multiple associations, or a changed subject — is cached and refreshed, never retried. - Caches definitive negatives. "Multiple associations" and "no association with a
NONEfallback" are cached as errorBrokerAssociatedNameStrategy.Resolutions for the normal refresh cycle, so they no longer hammer Schema Registry on every record; a later refresh that finds an association replaces the negative. - Preserves the original cause. Transient failures are thrown as a
SerializationExceptionwhose cause is the underlyingRestClientException/IOException, soRecordSchemaValidatorcan classify them onto the right error sensor.
subjectName(String, boolean, ParsedSchema) is fully overridden, so the parent's own
cache (built by super.configure) is never consulted.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAfter exhausting retries, how long (seconds) to short-circuit further lookups for the same key and rethrow the cached failure without calling Schema Registry.static final StringMax retries on a transient (IOException / 5xx) association lookup failure.static final StringWait, in milliseconds, between transient retries.Fields inherited from class io.confluent.kafka.serializers.subject.AssociatedNameStrategy
CACHE_EXPIRY_SECS, CACHE_SIZE, FALLBACK_TYPE, KAFKA_CLUSTER_ID, NAMESPACE_WILDCARD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidsetKafkaClusterId(String clusterId) voidsetSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient client) subjectName(String topic, boolean isKey, io.confluent.kafka.schemaregistry.ParsedSchema schema) Methods inherited from class io.confluent.kafka.serializers.subject.AssociatedNameStrategy
usesSchema
-
Field Details
-
MAX_RETRIES
Max retries on a transient (IOException / 5xx) association lookup failure.- See Also:
-
RETRIES_WAIT_MS
Wait, in milliseconds, between transient retries.- See Also:
-
FAILURE_BACKOFF_SECS
After exhausting retries, how long (seconds) to short-circuit further lookups for the same key and rethrow the cached failure without calling Schema Registry.<= 0disables backoff.- See Also:
-
-
Constructor Details
-
BrokerAssociatedNameStrategy
public BrokerAssociatedNameStrategy()
-
-
Method Details
-
configure
-
subjectName
public String subjectName(String topic, boolean isKey, io.confluent.kafka.schemaregistry.ParsedSchema schema) - Specified by:
subjectNamein interfaceio.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy- Overrides:
subjectNamein classio.confluent.kafka.serializers.subject.AssociatedNameStrategy
-
setSchemaRegistryClient
public void setSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient client) - Specified by:
setSchemaRegistryClientin interfaceio.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy- Overrides:
setSchemaRegistryClientin classio.confluent.kafka.serializers.subject.AssociatedNameStrategy
-
setKafkaClusterId
- Specified by:
setKafkaClusterIdin interfaceio.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy- Overrides:
setKafkaClusterIdin classio.confluent.kafka.serializers.subject.AssociatedNameStrategy
-