मैंने पढ़ा है के सेट-आधारित स्थिरता सत्यापन ब्लॉग और मैं चाहते हैं कि मान्य करने के लिए के माध्यम से एक प्रेषण इंटरसेप्टर. मैं उदाहरण का अनुसरण करें, लेकिन मैं का उपयोग करें प्रतिक्रियाशील भंडार नहीं है और यह वास्तव में मेरे लिए काम करते हैं. मैं दोनों की कोशिश की ब्लॉक और ब्लॉक नहीं. ब्लॉक के साथ यह त्रुटि फेंकता है, लेकिन बिना यह ब्लॉक अमल नहीं करता । यहाँ है मेरे कोड.
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
}
}
}