Class 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

invalid reference
io.confluent.kafka.serializers.KafkaAvroSerializer
as long as auto-registration of schemas is disabled.
  • Constructor Details

    • LruSchemaRegistryClient

      public 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

      public 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)
    • 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:
      getSchemaBySubjectAndId in interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
      Specified by:
      getSchemaBySubjectAndId in class AbstractSchemaRegistryClient
      Throws:
      IOException
      io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
    • isIdBanned

      public boolean isIdBanned(String subject, int id)
      Description copied from interface: CachedSchemaLookup
      True when id is known not to exist for subject, so the record can be rejected without consulting Schema Registry.
      Specified by:
      isIdBanned in interface CachedSchemaLookup
    • isGuidBanned

      public boolean isGuidBanned(String guid)
      Description copied from interface: CachedSchemaLookup
      True when guid is known not to exist, so the record can be rejected without consulting Schema Registry.
      Specified by:
      isGuidBanned in interface CachedSchemaLookup
    • 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: CachedSchemaLookup
      The cached schema for subject and id, or null on a cache miss. strategy, topic, isKey and contextName are used to resolve the subject for the follow-up schema-to-id lookup warmed on a miss.
      Specified by:
      getSchemaBySubjectAndIdIfCached in interface CachedSchemaLookup
    • getSchemaByGuid

      public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaByGuid(String guid, String format) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
      Specified by:
      getSchemaByGuid in interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
      Throws:
      IOException
      io.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: CachedSchemaLookup
      The cached schema for guid, or null on a cache miss. The remaining arguments serve the same purpose as in CachedSchemaLookup.getSchemaBySubjectAndIdIfCached(String, int, SubjectNameStrategy, String, boolean, String).
      Specified by:
      getSchemaByGuidIfCached in interface CachedSchemaLookup
    • 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:
      getId in interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
      Specified by:
      getId in class AbstractSchemaRegistryClient
      Throws:
      IOException
      io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
    • getIdIfCached

      public Integer getIdIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
      Description copied from interface: CachedSchemaLookup
      The cached id registered for schema under subject; null on a genuine cache miss (caller returns RETRY); CachedSchemaLookup.ID_ABSENT when the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.
      Specified by:
      getIdIfCached in interface CachedSchemaLookup
    • 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:
      getGuid in interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
      Specified by:
      getGuid in class AbstractSchemaRegistryClient
      Throws:
      IOException
      io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
    • getGuidIfCached

      public String getGuidIfCached(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema)
      Description copied from interface: CachedSchemaLookup
      The cached guid registered for schema under subject; null on a genuine cache miss (caller returns RETRY); CachedSchemaLookup.GUID_ABSENT when the schema is known not to be registered (caller rejects). See the three-way contract on the class javadoc.
      Specified by:
      getGuidIfCached in interface CachedSchemaLookup
    • reset

      public void reset()
      Specified by:
      reset in interface io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
      Overrides:
      reset in class AbstractSchemaRegistryClient