Axonframework, cum să utilizați MessageDispatchInterceptor cu reactiv depozit

0

Problema

Am citit stabilit pe baza consistenta de validare blog și vreau să valideze printr-un dispecerat de interceptare. Am urmat exemplul, dar eu folosesc reactive depozit și nu funcționează pentru mine. Am încercat atât de bloc si nu se blocheaza. cu bloc se aruncă eroare, dar fără bloc nu executa nimic. aici este codul meu.

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
    }
  }
}
axon axon-framework kotlin
2021-11-24 06:18:54
1

Cel mai bun răspuns

3

Abonarea la un reactivă depozit într-un mesaj dispecer nu este foarte recomandat și ar putea duce la un comportament ciudat, ca subaltern ThreadLocal (folosit de Axox) nu este adaptat pentru a fi folosit în reactivă de programare

În schimb, a verifica afară Axon Reactive Extensie și reactive de interceptare secțiune.

De exemplu ce ai putea face:

reactiveCommandGateway.registerDispatchInterceptor(
        cmdMono -> cmdMono.flatMap(cmd->privateNetworkRepository
      .findById(cmd.privateNetworkId))
.switchIfEmpty(
Mono.error(IllegalArgumentException("Requested subnet is overlap with the previous subnet."))
.then(cmdMono)));
2021-11-24 13:26:24

multumesc pentru sfat, btw nu vad nici ReactorCommandBus în extensie ar trebui să folosesc ReactroCommandGateway în loc?
Patrick

da, acolo sunt doar reactivă gateway-uri acceptate
schananas

În alte limbi

Această pagină este în alte limbi

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................