我正在使用Reactor 2和Spring4。这是我拥有的典型代码-Consumer
与存储库一起使用
@Consumer
public class ApplicationService {
@Selector(value="/applications/id", type = SelectorType.URI)
@ReplyTo
public Application byApplicationId(String id) throws ApplicationNotFoundException {
Application app = appRepo.findOne(id);
if(app == null)
throw new ApplicationNotFoundException("Application `" + id + "` could not be found.");
return app;
}
}
然后我有一个控制器,它将请求传递到eventBus
,我将请求传递到其中并返回Promise
@RestController
@RequestMapping("/applications")
public class ApplicationsController {
@RequestMapping(value = "/{id}", method = GET, produces = APPLICATION_JSON_VALUE)
public Promise<Event<Application>> byApplicationId(@PathVariable final String id) {
final Promise<Event<Application>> p = Promises.prepare(env);
eventBus.sendAndReceive("/applications/id", Event.wrap(id), p);
return p;
}
}
事情正常,但是如果ApplicationService
抛出异常Promise
的值未设置,但是我在控制台中得到了以下提示:
16:46:58.003 [main] ERROR reactor.bus.EventBus - null
java.lang.reflect.UndeclaredThrowableException
at org.springframework.util.ReflectionUtils.rethrowRuntimeException(ReflectionUtils.java:302)
...
Caused by: com.metlife.harmony.exceptions.ApplicationNotFoundException: Application `2860c555-0bc4-45e6-95ea-f724ae3f4464` could not be found.
at com.metlife.harmony.services.ApplicationService.byApplicationId(ApplicationService.java:46) ~[classes/:?]
...
Caused by: reactor.core.support.Exceptions$ValueCause: Exception while signaling value: reactor.bus.Event.class : Event{id=null, headers={}, replyTo=reactor.bus.selector.Selectors$AnonymousKey@4, key=/applications/id, data=2860c555-0bc4-45e6-95ea-f724ae3f4464}
问题是:
我是否以错误的方式使用Reactor和eventBus
?如果是这样,正确的方法是什么]]
也许此功能尚未实现
我正在使用Reactor 2和Spring4。这是我拥有的典型代码-使用仓库的使用者@Consumer公共类ApplicationService {@Selector(value =“ / applications / id”,键入...
我想我重新评估了在Spring应用程序中使用Reactor的策略。
现在我的控制器看起来像
阅读Reactive参考中用于处理异常和错误的专用章节:
https://projectreactor.io/docs/core/release/reference/#error.handling