J'ai lu l'ensemble basé sur la cohérence de validation blog et je tiens à valider par le biais d'un envoi de l'intercepteur. J'ai suivi l'exemple, mais j'utilise le réactif de dépôt et ça ne fonctionne pas vraiment pour moi. J'ai essayé les deux bloc et de ne pas bloquer. avec le bloc, il déclenche une erreur, mais sans bloquer il n'a pas d'exécuter quoi que ce soit. voici mon code.
class SubnetCommandInterceptor : MessageDispatchInterceptor<CommandMessage<*>> {
@Autowired
private lateinit var privateNetworkRepository: PrivateNetworkRepository
override fun handle(messages: List<CommandMessage<*>?>): BiFunction<Int, CommandMessage<*>, CommandMessage<*>> {
return BiFunction<Int, CommandMessage<*>, CommandMessage<*>> { index: Int?, command: CommandMessage<*> ->
if (CreateSubnetCommand::class.simpleName == (command.payloadType.simpleName)){
val interceptCommand = command.payload as CreateSubnetCommand
privateNetworkRepository
.findById(interceptCommand.privateNetworkId)
// ..some validation logic here ex.
// .filter { network -> network.isSubnetOverlap() }
.switchIfEmpty(Mono.error(IllegalArgumentException("Requested subnet is overlap with the previous subnet.")))
// .block() also doesn't work here it throws error
// block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-
}
command
}
}
}