简体   繁体   English

在Akka类型的actor中配置分派器

[英]Configure Dispatcher in Akka typed actors

I´m working with Akka typed, and I´m not able checking in the official documentation( https://doc.akka.io/docs/akka/current/typed/actors.html#actors ), which I found really short, how to configure the Dispatcher in the Actor typed. 我正在使用Akka打字,我无法检查官方文档( https://doc.akka.io/docs/akka/current/typed/actors.html#actors ),但我发现它确实很短,如何在Actor类型中配置Dispatcher。

Here an example of my code 这是我的代码示例

private int actorTimeout = Integer.parseInt(getProperty("environment.actor.timeout", "10"));

    @Autowired
    private AkkaTypedDAO akkaTypedDAO;

    private ActorSystem<AkkaTypedDTO> system;

    @PostConstruct
    private void initActor() {
        system = ActorSystem.create(akkaTypedDAO.daoWithSupervisor, "AkkaTypedDAO");
    }

    private final Behavior<CommandAkkaTyped> service = Actor.immutable((ctx, msg) -> {
        sendToDAO(msg.id).thenApply(either -> {
            msg.replyTo.tell(either);
            return either;
        });
        return Actor.same();
    });

    public final Behavior<CommandAkkaTyped> serviceWithSupervisor = Actor.supervise(service).onFailure(Exception.class, restart());

    private CompletionStage<Either<ConnectorErrorVO, EntityDaoDTO>> sendToDAO(MUSIn<AkkaTypedPayLoad> id) {
        return AskPattern.ask(system,
                (ActorRef<Either<ConnectorErrorVO, EntityDaoDTO>> replyTo) -> new AkkaTypedDTO(new EntityDaoDTO(musIn), replyTo),
                new Timeout(actorTimeout, TimeUnit.SECONDS), system.scheduler());
    }

When I create my ActorSystem how can I configure the dispatcher for my Actor.immutable? 创建ActorSystem时,如何为Actor.immutable配置调度程序?

You're using an outdated version of Akka Typed (see here for more information about the history of the Akka Typed API). 您正在使用过时的Akka Typed版本(有关Akka Typed API历史的更多信息,请参见此处 )。 From the current version (as of this writing, 2.5.14) of the Akka Typed documentation : Akka Typed文档的当前版本(撰写本文时为2.5.14):

To specify a dispatcher when spawning an actor use DispatcherSelector . 要在生成actor时指定调度程序,请使用DispatcherSelector If not specified, the actor will use the default dispatcher, see Default dispatcher for details. 如果未指定,则actor将使用默认调度程序,有关详细信息,请参见默认调度程序。

public static final Behavior<Start> main =
  Behaviors.setup(context -> {
    final String dispatcherPath = "akka.actor.default-blocking-io-dispatcher";

    Props props = DispatcherSelector.fromConfig(dispatcherPath);
    final ActorRef<HelloWorld.Greet> greeter =
      context.spawn(HelloWorld.greeter, "greeter", props);

    return Behaviors.receiveMessage(msg -> {
      ActorRef<HelloWorld.Greeted> replyTo =
          context.spawn(HelloWorldBot.bot(0, 3), msg.name);
      greeter.tell(new HelloWorld.Greet(msg.name, replyTo));
      return Behaviors.same();
    });
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM