Class RecordSchemaValidator

java.lang.Object
io.confluent.kafka.schemaregistry.validator.RecordSchemaValidator
All Implemented Interfaces:
SchemaValidationContext, Closeable, AutoCloseable, org.apache.kafka.common.Configurable, org.apache.kafka.server.interceptor.RecordInterceptor

public class RecordSchemaValidator extends Object implements org.apache.kafka.server.interceptor.RecordInterceptor, SchemaValidationContext
A RecordInterceptor that performs schema validation. This interceptor checks that

1) The record payload has a magic byte, then followed by a schema id integer encoded in the next 4 bytes.

2) The encoded schema id exists in the Schema Registry, and is registered under the subject matching the topic.

If both 1) and 2) are true, then the interceptor will return ACCEPT, otherwise return REJECT.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.kafka.server.interceptor.RecordInterceptor

    org.apache.kafka.server.interceptor.RecordInterceptor.RecordInterceptorResponse
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    RecordSchemaValidator(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient schemaRegistry, org.slf4j.Logger log)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether validation may answer from cache and return ValidationDecision.RETRY.
    void
     
    void
    configure(Map<String,?> configs)
     
    Schema Registry context to qualify subjects with, or null/default for none.
    org.slf4j.Logger
    Logger to attribute validation failures to.
    org.apache.kafka.common.utils.TimeBasedSampler
    Rate limiter for per-record failure logging, so one bad producer cannot flood the log.
    Where validation metrics are recorded.
    org.apache.kafka.server.interceptor.RecordInterceptor.RecordInterceptorResponse
    onAppend(org.apache.kafka.common.TopicPartition tp, org.apache.kafka.common.record.internal.Record record)
     
    io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
    The Schema Registry to validate against.
    io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy
    subjectNameStrategy(boolean isKey)
    The subject-name strategy for the key or the value.
    boolean
     
    boolean
     
    boolean
    Whether to look for a schema guid in the record headers before falling back to the payload.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.kafka.server.interceptor.RecordInterceptor

    setMetrics

    Methods inherited from interface SchemaValidationContext

    cachedSchemaLookup