Questo contenuto non è disponibile nella lingua selezionata.

Chapter 1. (Preview) Record Validation filter


The Record Validation filter validates records sent by a producer. Only records that pass the validation are sent to the broker. This filter can be used to prevent poison messages—such as those containing corrupted data or invalid formats—from entering the Kafka system, which may otherwise lead to consumer failure.

The filter currently supports two modes of operation:

  1. Schema Validation ensures the content of the record conforms to a schema stored in an Apicurio Registry.
  2. JSON Syntax Validation ensures the content of the record contains syntactically valid JSON.

Validation rules can be applied to check the content of the Kafka record key or value.

If the validation fails, the product request is rejected and the producing application receives an error response. The broker will not receive the rejected records.

Note

This filter is currently in incubation and available as a preview. We would not recommend using it in a production environment.

1.1. (Preview) Setting up the Record Validation filter

This procedure describes how to set up the Record Validation filter. Provide the filter configuration and rules that the filter uses to check against Kafka record keys and values.

Prerequisites

  • An instance of Streams for Apache Kafka Proxy. For information on deploying Streams for Apache Kafka Proxy, see the samples and examples.
  • A config map for Streams for Apache Kafka Proxy that includes the configuration for creating a virtual cluster.
  • Apicurio Registry (if wanting to use Schema validation).

Procedure

  1. Configure a RecordValidation type filter.
rules:
  - topicNames:                  
1

      - <topic name>
    keyRule:                     
2

      <rule definition>
    valueRule:                   
3

      <rule definition>
defaultRule:                     
4

  keyRule:                       
5

    <rule definition>
  valueRule:                     
6

    <rule definition>
1
List of topic names to which the validation rules will be applied.
2 5
Validation rules that are applied to the record’s key.
3 6
Validation rules that are applied to the record’s value.
4
(Optional) Default rule that is applied to any topics for which there is no explict rule defined.

Replace the token <rule definition> in the YAML configuration with either a Schema Validation rule or a JSON Syntax Validation rule depending on your requirements.

Example Schema Validation Rule Definition

The Schema Validation rule validates that the key or value matches a schema identified by its global ID within an Apicurio Schema Registry.

If the key or value does not adhere to the schema, the record will be rejected.

Additionally, if the kafka producer has embedded a global ID within the record it will be validated against the global ID defined by the rule. If they do not match, the record will be rejected. See the Apicurio documentation for details on how the global ID could be embedded into the record. The filter supports extracting ID’s from either the Apicurio globalId record header or from the initial bytes of the serialized content itself.

schemaValidationConfig:
    apicurioGlobalId: 1001                                       
1

    apicurioRegistryUrl: http://registry.local:8080              
2

allowNulls: true                                                 
3

allowEmpty: true                                                 
4
1
Apicurio registry global ID identifying the schema that will be enforced.
2
Apicurio Registry endpoint.
3
if true, the validator allows keys and or values to be null. The default is false.
4
if true, the validator allows keys and or values to be empty. The default is false.
Note

Schema validation mode currently has the capability to enforce only JSON schemas (issue)

Example JSON Syntax Validation Rule Definition

The JSON Syntax Validation rule validates that the key or value contains only syntactically correct JSON.

syntacticallyCorrectJson:
    validateObjectKeysUnique: true                               
1

allowNulls: true                                                 
2

allowEmpty: true                                                 
3
1
If true, the validator enforces that objects keys must be unique. The default is false.
2
if true, the validator allows keys and or values to be null. The default is false.
3
if true, the validator allows keys and or values to be empty. The default is false.
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat
Torna in cima