【发布时间】:2021-06-18 15:09:53
【问题描述】:
1 customerRepo.findById(customerId) // finding the Customer
2 .switchIfEmpty(Mono.defer(
() -> Mono.error(new RuntimeException("not found")))) // if empty throw error
3 .filter(customer -> StringUtils.isEmpty(customer.getType().equals("Regular"))) // add filter condition
4 .switchIfEmpty(Mono.defer(
() -> Mono.error(new RuntimeException("no regualar customer")))) // If empty throw error
5 flatMap....... (logic continues)
- 根据来自 DB 的 ID 查找客户。
- 如果未找到客户 ID 的客户,则会引发错误。
- 检查是否有老客户。
- 如果没有固定客户,则使用不同的消息引发异常。
- 那么我还有进一步的逻辑要继续。
问题:
- 这是完全反应式编写的正确方法吗?
- 当我连续点击时,我在第 4 行收到 java.lang.RuntimeException: 错误。 (注意:如果客户不在,我不会收到 RuntimeException 第 2 行)
- 在编写逻辑的正确方法方面需要帮助。
【问题讨论】:
标签: spring-boot mono spring-webflux project-reactor flux