Kest

Search

Search the documentation

Microservices

Pipes

Validate message payloads.

A message's payload is decoded into your parameter type, and ValidationPipe checks its constraint annotations, so a bad message is rejected before the handler runs.

data class SumRequest(@field:Size(min = 1, max = 100) val numbers: List<Int>)
 
@MessagePattern("sum") fun sum(@UsePipes(ValidationPipe::class) req: SumRequest): Int = req.numbers.sum()

The caller of client.send("sum", ...) receives an RpcException with status 400 and the validation message. For events (@EventPattern) there is nobody to answer: an invalid event is logged and dropped, so validate there too and decide what to do (a dead-letter topic) in the handler.

Do not trust other services' data just because they are yours: a bug or an old version can send anything. See Pipes and Validation.

Read more