Axonframework ยังต้องใช้ MessageDispatchInterceptor กับ reactive เก็บ

0

คำถาม

ฉันต้องอ่านที่ตั้งค่า-จาก มุมมการตรวจสอบบล็อก และฉันอยากจะพิสูจน์ความถูกต้องขอผ่านส่ interceptor. ฉันทำตามกตัวอย่างเช่นแต่ฉันใช้ reactive เก็บและมันไม่ได้ผลสำหรับฉัน ฉันพยายามทั้งสองบล็อกและไม่ใช่แบบเดียวกันหมด กับบล็อคทำให้เกิดข้อผิดพลาด,แต่ไม่มีบล็อกมันไม่ได้เรียกประมวลผลอะไรเลย นี่คือตอบสนองรหัสผม

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

Subscribing ต้องเป็น reactive เก็บข้างในข้อความ dispatcher มันไม่จริงแนะนำให้และอาจจะนำไปสู่พฤติกรรมแปลกๆที่ underling ThreadLocal(ถูกใช้โดย Axox) ยังไม่พัฒนาเป็นเพื่อใช้ใน reactive programing

แทนที่จะตรวจสอ Axon น Reactive ส่วนขยาย และ reactive interceptors นส่วนของตัวเอง

ตัวอย่างเช่นอะไรคุณอาจจะทำอย่าง:

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

ขอบคุณสำหรับคำแนะนำ btw ฉันไม่เห็นอะไร ReactorCommandBus อยู่ในส่วนขยายฉันควรจะใช้ ReactroCommandGateway นไปแทนงั้นเหรอ?
Patrick

ใช่มีเพียง reactive gateways การรองรับ
schananas

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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