Axonframework,如何使用MessageDispatchInterceptor与反应仓库

0

的问题

我读过基于数据集的 一致性验证的博客 和我想要验证通过一个调度拦截。 我跟着的例子,但我采用的反应仓库和它并不真正为我工作。 我已经尝试了两块和不块。 与阻止它投错误的,但没有阻止它不执行任何东西。 这里是我的代码。

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

最好的答案

3

订阅的一个反应的存储库的内部消息调度员是不是真的建议和可能会导致怪异的行为作为下属线程本地(使用由Axox) 不适于使用的反应程序

相反,检查出 轴突的反应延长 和反应性的拦截部分。

例如什么你可能会做的事:

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

谢谢你的建议,顺便说一句我没有看到任何ReactorCommandBus在扩展我应该使用ReactroCommandGateway,而不是?
Patrick

是的,有的只是反应性支持的网关
schananas

其他语言

此页面有其他语言版本

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