Reputation: 13471
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.
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?
Upvotes: 1
Views: 412
Reputation: 19517
You're using an outdated version of Akka Typed (see here for more information about the history of the Akka Typed API). From the current version (as of this writing, 2.5.14) of the Akka Typed documentation:
To specify a dispatcher when spawning an actor use DispatcherSelector. If not specified, the actor will use the default dispatcher, see Default dispatcher for details.
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();
});
});
Upvotes: 2