【发布时间】:2021-01-12 22:10:38
【问题描述】:
目前我正在使用 Akka,我有以下协议。
在我的协议中,我有一个只负责创建资源(房间和 gabblers)的服务器。这些资源被创建然后被访问。接下来,我想通过一个键找到相应的 Gabbler ActorRef 来发送消息,但这一次是从一个公开了一个不是演员的 API/方法的类中。我已经看过文档,令我难以置信的是,演员系统中没有一种方法可以从其层次结构中返回特定的演员来使用它。我已经阅读了接待员部分,虽然对我来说不是很清楚,但我看到它再次面向演员。 Akka中没有根据Actor的路径返回引用的方法吗?
package co.test;
import akka.actor.typed.ActorSystem;
import akka.actor.typed.javadsl.AskPattern;
import akka.actor.typed.receptionist.Receptionist;
import co.test.actors.ChatServer;
public class ChatServerApplication {
public static void main(String[] args) {
ActorSystem<ChatServer.ServerCommand> system =
ActorSystem.create(ChatServer.create(), "chat-server");
system.tell(new ChatServer.NewEventRoom("room1"));
system.tell(new ChatServer.AttendeeJoin("room1", "user1"));
system.tell(new ChatServer.AttendeeJoin("room1", "user2"));
system.tell(new ChatServer.AttendeeJoin("room1", "user3"));
system.tell(new ChatServer.AttendeeJoin("room1", "user4"));
system.tell(new ChatServer.AttendeeJoin("room1", "user5"));
system.tell(new ChatServer.AttendeeJoin("room1", "user6"));
system.tell(new ChatServer.AttendeeJoin("room1", "user7"));
//ActorRef<Gabbler.Command> gabbler = get specific Gabbler ActorRef
//gabbler.tell(new Gabbler.SendMessage("test");
}
}
上图中的协议已经实现,但我无法理解上面的问题。
【问题讨论】:
标签: java akka akka-typed