PatternsCS.ask is Deprecated I need the alternative when using Akka HTTP

akka-http
(David Watson) #1

In the quickstart guide for Akka Http: https://developer.lightbend.com/guides/akka-http-quickstart-java/http-server.html there is this snippet of code being used:

       CompletionStage<ActionPerformed> userCreated = PatternsCS
                            .ask(userRegistryActor, new CreateUser(user), timeout)
                            .thenApply(obj ->(ActionPerformed) obj);

However PatternsCS is deprecated. I’m currently unable to find an alternative when using Akka Http. I’ve found many solutions using Akka but I can’t seem to get my head around how to transfer this into Akka Http.
Any help will be greatly appreciated.
Thanks
David

(Tim Moore) #2

It looks like this example was updated after you posted this, but it could still be improved further.

The simplest fix would be to change timeout to a java.time.Duration instance and then use Patterns.ask instead of PatternsCS.

(David Watson) #3

Thanks for getting back to me Tim. I’ve now fixed it as per the new quickstart guide.