In akka version 2.5.2, I implemented to call akka actor using Patters.ask which return the Futures as you can see in below example.
@SuppressWarnings("unchecked")
Future<Task> future = (Future<Task>)(Future<?>)Patterns
.ask(workerActor, TaskRequest, totalAskTimeout);
Currently , I am implementing the akka cluster actor using akka-typed-2.13 version 2.6.4 where actors are replaced with behaviors.So I have below service actor which return the response but how can I use this response to pass in the another class which is not static or akka class.
Below is my example, ServiceResponse will be called as call back but how can I call this method from another class which is implemented as rest service. In other words, I want to call RunService (which is implemented as below ) from the rest service ClientRequest.
public static Behavior<Event> create(ActorRef<RunService.RunFactorialNumber> service) {
return Behaviors.setup(context ->
Behaviors.withTimers(timers -> {
timers.startTimerWithFixedDelay(Tick.INSTANCE, Tick.INSTANCE, Duration.ofSeconds(100));
ActorRef<RunService.Response> responseAdapter =
context.messageAdapter(RunService.Response.class, ServiceResponse::new);
return Behaviors.receive(Event.class)
.onMessageEquals(Tick.INSTANCE, () -> {
context.getLog().info("Sending process request");
int fib =111;
service.tell(new RunService.RunFactorialNumber(fib++, responseAdapter));
return Behaviors.same();
}).onMessage(ServiceResponse.class, response -> {
context.getLog().info("Service result: {}", response.result);
nextStep(response.result.toString());
return Behaviors.same();
}).build();
})
);
}