Request Rule Validator

Enforce producer and consumer settingsv1.3+

This Request Rule Validator policy enforces client settings on Produce and Fetch requests.

In this example, for produce requests:

  • Producers must set acks to all (-1), so that every in-sync replica stores a record before the broker acknowledges it.
  • If a producer uses transactions, its transactional ID must start with team-a..

For fetch requests:

  • Consumers must use the read_committed isolation level, so that they don’t read records from aborted transactions.
  • Consumers must set fetch.max.wait.ms to at least 100 ms, so that the broker can hold a fetch until data is available instead of returning empty responses in a tight loop.
  • A fetch response can be at most 50 MiB (fetch.max.bytes).

The default fetch settings of most Kafka clients match these limits: consumers set fetch.max.wait.ms to 500 ms and fetch at most 50 MiB. Most clients use read_uncommitted by default, so consumers must set isolation.level=read_committed explicitly. A consumer that breaks a fetch rule doesn’t receive any records. For example, the Java consumer stops with IllegalStateException: Unexpected error code 44.

When a request doesn’t match a rule, Event Gateway rejects the entire request with the Kafka POLICY_VIOLATION error code. The Produce and Fetch responses don’t carry an error message, so clients only receive the error code, not the rule description.

A producer with acks=0 doesn’t wait for a response. If Event Gateway rejects its records, the producer doesn’t receive an error, and the records are lost.

Set up the policy

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!