Přečetl jsem si nastavit-podle konzistence ověření blog a chci ověřit prostřednictvím odeslání interceptor. Jsem následovat příklad, ale já používám reaktivní úložiště a to opravdu není práce pro mě. Snažil jsem se oba blok a ne blokovat. s blokem to hází error, ale bez bloku to nespustí nic. tady 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
}
}
}