Class LruSchemaRegistryClient

java.lang.Object
io.confluent.kafka.schemaregistry.validator.AbstractSchemaRegistryClient
io.confluent.kafka.schemaregistry.validator.LruSchemaRegistryClient
All Implemented Interfaces:
io.confluent.kafka.schemaregistry.client.SchemaRegistryClient, io.confluent.kafka.schemaregistry.client.SchemaVersionFetcher, Closeable, AutoCloseable

public class LruSchemaRegistryClient extends AbstractSchemaRegistryClient
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)
    • 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)
    • 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)
  • Method Details

    • parseSchema

      public Optional<io.confluent.kafka.schemaregistry.ParsedSchema> parseSchema(String schemaType, String schemaString, List<io.confluent.kafka.schemaregistry.client.rest.entities.SchemaReference> references)
    • parseSchema

      public Optional<io.confluent.kafka.schemaregistry.ParsedSchema> parseSchema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema schema)
    • 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
    • getSchemaByGuid

      public io.confluent.kafka.schemaregistry.ParsedSchema getSchemaByGuid(String guid, String format) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
      Throws:
      IOException
      io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
    • getByVersion

      public io.confluent.kafka.schemaregistry.client.rest.entities.Schema getByVersion(String subject, int version, boolean lookupDeletedSchema)
    • 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
    • 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
    • getIdWithResponse

      public io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaResponse getIdWithResponse(String subject, io.confluent.kafka.schemaregistry.ParsedSchema schema, boolean normalize) throws IOException, io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
      Throws:
      IOException
      io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException
    • reset

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

      public void close() throws IOException
      Throws:
      IOException