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
ConstructorsConstructorDescriptionRecordSchemaValidator(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient schemaRegistry, org.slf4j.Logger log) -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether validation may answer from cache and returnValidationDecision.RETRY.voidclose()voidSchema Registry context to qualify subjects with, or null/default for none.org.slf4j.Loggerlogger()Logger to attribute validation failures to.org.apache.kafka.common.utils.TimeBasedSamplerRate limiter for per-record failure logging, so one bad producer cannot flood the log.metrics()Where validation metrics are recorded.org.apache.kafka.server.interceptor.RecordInterceptor.RecordInterceptorResponseonAppend(org.apache.kafka.common.TopicPartition tp, org.apache.kafka.common.record.internal.Record record) io.confluent.kafka.schemaregistry.client.SchemaRegistryClientThe Schema Registry to validate against.io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategysubjectNameStrategy(boolean isKey) The subject-name strategy for the key or the value.booleanbooleanbooleanWhether 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, waitMethods inherited from interface org.apache.kafka.server.interceptor.RecordInterceptor
setMetricsMethods inherited from interface SchemaValidationContext
cachedSchemaLookup
-
Constructor Details
-
RecordSchemaValidator
public RecordSchemaValidator() -
RecordSchemaValidator
public RecordSchemaValidator(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient schemaRegistry, org.slf4j.Logger log)
-
-
Method Details
-
configure
-
onAppend
public org.apache.kafka.server.interceptor.RecordInterceptor.RecordInterceptorResponse onAppend(org.apache.kafka.common.TopicPartition tp, org.apache.kafka.common.record.internal.Record record) - Specified by:
onAppendin interfaceorg.apache.kafka.server.interceptor.RecordInterceptor
-
schemaRegistry
public io.confluent.kafka.schemaregistry.client.SchemaRegistryClient schemaRegistry()Description copied from interface:SchemaValidationContextThe Schema Registry to validate against.- Specified by:
schemaRegistryin interfaceSchemaValidationContext
-
subjectNameStrategy
public io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy subjectNameStrategy(boolean isKey) Description copied from interface:SchemaValidationContextThe subject-name strategy for the key or the value.- Specified by:
subjectNameStrategyin interfaceSchemaValidationContext
-
contextName
Description copied from interface:SchemaValidationContextSchema Registry context to qualify subjects with, or null/default for none.- Specified by:
contextNamein interfaceSchemaValidationContext
-
validateKey
public boolean validateKey()- Specified by:
validateKeyin interfaceSchemaValidationContext
-
validateValue
public boolean validateValue()- Specified by:
validateValuein interfaceSchemaValidationContext
-
validateWithGuid
public boolean validateWithGuid()Description copied from interface:SchemaValidationContextWhether to look for a schema guid in the record headers before falling back to the payload.- Specified by:
validateWithGuidin interfaceSchemaValidationContext
-
asyncValidationEnabled
public boolean asyncValidationEnabled()Description copied from interface:SchemaValidationContextWhether validation may answer from cache and returnValidationDecision.RETRY.- Specified by:
asyncValidationEnabledin interfaceSchemaValidationContext
-
metrics
Description copied from interface:SchemaValidationContextWhere validation metrics are recorded. UseValidationMetricsRecorder.NOOPfor none.- Specified by:
metricsin interfaceSchemaValidationContext
-
logger
public org.slf4j.Logger logger()Description copied from interface:SchemaValidationContextLogger to attribute validation failures to.- Specified by:
loggerin interfaceSchemaValidationContext
-
loggingSampler
public org.apache.kafka.common.utils.TimeBasedSampler loggingSampler()Description copied from interface:SchemaValidationContextRate limiter for per-record failure logging, so one bad producer cannot flood the log.- Specified by:
loggingSamplerin interfaceSchemaValidationContext
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.apache.kafka.server.interceptor.RecordInterceptor
-