在Akka-Java中有以下问题。Akka-Java路由问题
我有一个父代演员MainActor.class
,这个父代有5个子代路由。以下是层次结构:
My App => Main Actor => [Child Route-1,Child-Route-2,..]
简单的例子是字符串输入进行解析,以整数作为输出:
MyApp ===ask[string input]===> Main Actor ==route==> Child(parses to Integer) === integer result===> Main Actor ===result==> MyApp
以下是主要演员片段:
class MainActor extends UntypedActor {
Router router; {
// ...routes are configured here
}
public void onReceive(Object message) {
if (message instanceof String) {
router.route(message, self()); // route it to child
} else if (message instanceof Integer) {
// received from child, 'tell' this result to actual sender/parent i.e, MyApp
sender().tell(message, self());
} else unhandled(message);
}
}
并且Child Actor除了将String解析为Integer外,并将结果发回给发件人sender().tell(result,getContext().parent())
问题
MainActor
派遣由孩子送到解析的整数结果返回给孩子本身,而不是MyApp
。我也尝试将替换为MainActor
中的getContext().parent()
,但仍然无效。
我尝试将'sender()'替换为'getContext()。parent()',正如我在帖子中提到的那样,没有运气。 –