Axonframework, reaktif depo ile MessageDispatchInterceptor nasıl kullanılır

0

Soru

Set tabanlı tutarlılık doğrulama blogunu okudum ve bir gönderme engelleyicisi aracılığıyla doğrulamak istiyorum. Örneği takip ediyorum, ancak reaktif depo kullanıyorum ve bu benim için gerçekten işe yaramıyor. Hem engellemeyi hem de engellememeyi denedim. blok ile hata atar, ancak blok olmadan hiçbir şey yürütmez. işte kodum.

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

En iyi cevabı

3

Bir ileti dağıtıcısının içindeki reaktif bir depoya abone olmak gerçekten önerilmez ve ThreadLocal (Axox tarafından kullanılır) reaktif programlamada kullanılmak üzere uyarlanmadığından garip davranışlara neden olabilir

Bunun yerine, Axon'un Reaktif Uzatma ve reaktif önleyiciler bölümüne bakın.

Örneğin ne yapabilirsin:

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

tavsiye için teşekkürler, btw uzantıda herhangi bir ReactorCommandBus görmüyorum bunun yerine ReactroCommandGateway kullanmalı mıyım?
Patrick

evet, yalnızca reaktif ağ geçitleri desteklenir
schananas

Diğer dillerde

Bu sayfa diğer dillerde

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