Prečítal som si set-založené súlad overenie blogu a chcem overiť prostredníctvom odoslanie interceptor. Som nasledovať príklad, ale som pouţitie reaktívnych úloţiska a to nie je naozaj pre mňa pracovať. Snažil som sa obaja blok a nie bloku. s blokom to hodí chyba, ale bez blok nemusí vykonať nič. tu je môj kód.
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
}
}
}