Package com.babelqueue.schema
Class SchemaValidation
java.lang.Object
com.babelqueue.schema.SchemaValidation
Optional per-URN
data schema validation for a babelqueue producer or consumer
(ADR-0024). A SchemaProvider supplies a JSON Schema for a message URN — typically
built from a babelqueue-registry registry.json — and the message's data is
validated against it. It is opt-in: a URN with no registered schema is never validated.
- Producer-side (recommended): call
validate(com.babelqueue.schema.SchemaProvider, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>)before publishing so invalid data never enters the queue, orcheck(com.babelqueue.schema.SchemaProvider, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>)to branch without throwing. - Consumer-side (safety net): wrap a handler with
wrap(com.babelqueue.schema.SchemaProvider, com.babelqueue.idempotency.Handler). Invalid data throwsInvalidPayloadException, so the adapter redelivers (and eventually dead-letters) the poison message; a URN with no schema runs the handler unchanged. It reuses the sharedHandlerso it composes withIdempotent.wrap.
The Java mirror of the Go schema.Check/schema.Wrap helpers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe firstdataviolation for(urn, data), ornullwhen it is valid or when no schema is registered for the URN (opt-in).static voidValidate(urn, data)against its registered schema, throwing otherwise.static Handlerwrap(SchemaProvider provider, Handler handler) Returnshandlerwrapped to validate each message'sdataagainst its URN's schema before the handler runs (consumer-side safety net).
-
Method Details
-
check
The firstdataviolation for(urn, data), ornullwhen it is valid or when no schema is registered for the URN (opt-in). For producer-side branching.- Parameters:
provider- the schema sourceurn- the message URNdata- the message data- Returns:
- the first violation, or null
-
validate
Validate(urn, data)against its registered schema, throwing otherwise. The producer-side guard; call it before publishing.- Parameters:
provider- the schema sourceurn- the message URNdata- the message data- Throws:
InvalidPayloadException- when the data does not match the URN's schema
-
wrap
Returnshandlerwrapped to validate each message'sdataagainst its URN's schema before the handler runs (consumer-side safety net).- Parameters:
provider- the schema sourcehandler- the handler to guard- Returns:
- the wrapped handler
-