Class LruSchemaRegistryClient
java.lang.Object
io.confluent.kafka.schemaregistry.validator.AbstractSchemaRegistryClient
io.confluent.kafka.schemaregistry.validator.RestBackedSchemaRegistryClient
io.confluent.kafka.schemaregistry.validator.LruSchemaRegistryClient
- All Implemented Interfaces:
io.confluent.kafka.schemaregistry.client.SchemaRegistryClient, io.confluent.kafka.schemaregistry.client.SchemaVersionFetcher, CachedSchemaLookup, Closeable, AutoCloseable
public class LruSchemaRegistryClient
extends RestBackedSchemaRegistryClient
implements CachedSchemaLookup
An implementation of
SchemaRegistryClient that
only supports SchemaRegistryClient.getSchemaBySubjectAndId(String, int) and
SchemaRegistryClient.getId(String, ParsedSchema).
It uses LRU caches to hold the results of these two methods.
This class is thread-safe as the underlying caches are also thread-safe.
This class can still be used with
as
long as auto-registration of schemas is disabled.invalid reference
io.confluent.kafka.serializers.KafkaAvroSerializer
-
Field Summary
Fields inherited from interface CachedSchemaLookup
GUID_ABSENT, ID_ABSENT -
Constructor Summary
ConstructorsConstructorDescriptionLruSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.rest.RestService restService, int maxCacheSize, int maxRetries, int retriesWaitMs, Map<String, ?> configs, Map<String, String> httpHeaders, com.google.common.base.Ticker ticker, int missingIdQueryRange, long missingIdCacheTtl, long missingSchemaCacheTtl, long schemaCacheTtl) LruSchemaRegistryClient(List<String> baseUrls, int maxCacheSize, int maxRetries, int retriesWaitMs, Map<String, ?> configs, Map<String, String> httpHeaders, int missingIdQueryRange, long missingIdCacheTtl, long missingSchemaCacheTtl, long schemaCacheTtl) LruSchemaRegistryClient(List<String> baseUrls, int maxCacheSize, int maxRetries, int retriesWaitMs, Map<String, ?> configs, Map<String, String> httpHeaders, com.google.common.base.Ticker ticker, int missingIdQueryRange, long missingIdCacheTtl, long missingSchemaCacheTtl, long schemaCacheTtl) -
Method Summary
Modifier and TypeMethodDescriptiongetGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema) The cached guid registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);CachedSchemaLookup.GUID_ABSENTwhen the schema is known not to be registered (caller rejects).intgetIdIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema) The cached id registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);CachedSchemaLookup.ID_ABSENTwhen the schema is known not to be registered (caller rejects).io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaByGuid(String guid, String format) io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaByGuidIfCached(String guid, String subject, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) The cached schema forguid, or null on a cache miss.io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaBySubjectAndId(String subject, int id) io.confluent.kafka.schemaregistry.ParsedSchemagetSchemaBySubjectAndIdIfCached(String subject, int id, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) The cached schema forsubjectandid, or null on a cache miss.booleanisGuidBanned(String guid) True whenguidis known not to exist, so the record can be rejected without consulting Schema Registry.booleanisIdBanned(String subject, int id) True whenidis known not to exist forsubject, so the record can be rejected without consulting Schema Registry.voidreset()Methods inherited from class RestBackedSchemaRegistryClient
close, getAssociationsByResourceName, getByVersion, getIdWithResponse, parseSchema, parseSchemaMethods inherited from class AbstractSchemaRegistryClient
deleteSchemaVersion, deleteSchemaVersion, deleteSubject, deleteSubject, getAllSubjects, getAllSubjectsById, getAllVersions, getById, getByID, getBySubjectAndId, getBySubjectAndID, getCompatibility, getGuid, getId, getId, getLatestSchemaMetadata, getMode, getMode, getSchemaById, getSchemaMetadata, getVersion, getVersion, register, register, register, register, setMode, setMode, testCompatibility, testCompatibility, updateCompatibilityMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
batchGetAssociations, createAssociation, createOrUpdateAssociation, deleteAssociations, deleteCompatibility, deleteConfig, deleteMode, deleteSchemaVersion, deleteSchemaVersion, deleteSubject, deleteSubject, getAllContexts, getAllSubjects, getAllSubjectsByPrefix, getAllVersions, getAllVersionsById, getAssociationsByResourceId, getAssociationsBySubject, getCompatibility, getConfig, getConfig, getIdWithRequestResponse, getLatestSchemaMetadata, getLatestWithMetadata, getSchemaEntityBySubjectAndId, getSchemaMetadata, getSchemaMetadata, getSchemaRegistryDeployment, getSchemaRegistryServerVersion, getSchemas, getVersion, mutateAssociations, parseSchema, parseSchemaOrElseThrow, register, registerWithRequestResponse, registerWithResponse, registerWithResponse, setMode, tenant, testCompatibilityVerbose, testCompatibilityVerbose, testCompatibilityVerboseWithRequest, ticker, updateConfig
-
Constructor Details
-
LruSchemaRegistryClient
-
LruSchemaRegistryClient
-
LruSchemaRegistryClient
public LruSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.rest.RestService restService, int maxCacheSize, int maxRetries, int retriesWaitMs, Map<String, ?> configs, Map<String, String> httpHeaders, com.google.common.base.Ticker ticker, int missingIdQueryRange, long missingIdCacheTtl, long missingSchemaCacheTtl, long schemaCacheTtl)
-
-
Method Details
-
getSchemaBySubjectAndId
public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaBySubjectAndId(String subject, int id) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException - Specified by:
getSchemaBySubjectAndIdin interfaceio.confluent.kafka.schemaregistry.client.SchemaRegistryClient- Specified by:
getSchemaBySubjectAndIdin classAbstractSchemaRegistryClient- Throws:
IOExceptionio.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
-
isIdBanned
Description copied from interface:CachedSchemaLookupTrue whenidis known not to exist forsubject, so the record can be rejected without consulting Schema Registry.- Specified by:
isIdBannedin interfaceCachedSchemaLookup
-
isGuidBanned
Description copied from interface:CachedSchemaLookupTrue whenguidis known not to exist, so the record can be rejected without consulting Schema Registry.- Specified by:
isGuidBannedin interfaceCachedSchemaLookup
-
getSchemaBySubjectAndIdIfCached
public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaBySubjectAndIdIfCached(String subject, int id, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) Description copied from interface:CachedSchemaLookupThe cached schema forsubjectandid, or null on a cache miss.strategy,topic,isKeyandcontextNameare used to resolve the subject for the follow-up schema-to-id lookup warmed on a miss.- Specified by:
getSchemaBySubjectAndIdIfCachedin interfaceCachedSchemaLookup
-
getSchemaByGuid
public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaByGuid(String guid, String format) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException - Specified by:
getSchemaByGuidin interfaceio.confluent.kafka.schemaregistry.client.SchemaRegistryClient- Throws:
IOExceptionio.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
-
getSchemaByGuidIfCached
public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaByGuidIfCached(String guid, String subject, io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy strategy, String topic, boolean isKey, String contextName) Description copied from interface:CachedSchemaLookupThe cached schema forguid, or null on a cache miss. The remaining arguments serve the same purpose as inCachedSchemaLookup.getSchemaBySubjectAndIdIfCached(String, int, SubjectNameStrategy, String, boolean, String).- Specified by:
getSchemaByGuidIfCachedin interfaceCachedSchemaLookup
-
getId
public int getId(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema, boolean normalize) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException - Specified by:
getIdin interfaceio.confluent.kafka.schemaregistry.client.SchemaRegistryClient- Specified by:
getIdin classAbstractSchemaRegistryClient- Throws:
IOExceptionio.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
-
getIdIfCached
Description copied from interface:CachedSchemaLookupThe cached id registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);CachedSchemaLookup.ID_ABSENTwhen the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.- Specified by:
getIdIfCachedin interfaceCachedSchemaLookup
-
getGuid
public String getGuid(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema, boolean normalize) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException - Specified by:
getGuidin interfaceio.confluent.kafka.schemaregistry.client.SchemaRegistryClient- Specified by:
getGuidin classAbstractSchemaRegistryClient- Throws:
IOExceptionio.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
-
getGuidIfCached
public String getGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema) Description copied from interface:CachedSchemaLookupThe cached guid registered forschemaundersubject;nullon a genuine cache miss (caller returnsRETRY);CachedSchemaLookup.GUID_ABSENTwhen the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.- Specified by:
getGuidIfCachedin interfaceCachedSchemaLookup
-
reset
public void reset()- Specified by:
resetin interfaceio.confluent.kafka.schemaregistry.client.SchemaRegistryClient- Overrides:
resetin classAbstractSchemaRegistryClient
-