Mix Akka 2, Play2-mini framework and HTTP

With the release of Akka 2, Akka HTTP modules have been replaced with the Play2-mini option, where the Play2-mini looks like a Play2 playback controller minus the models.

A line stands out between the implementation of the REST service and the creation of the HTTP client. For example, I want to create a web service (not necessarily REST) ​​and an HTTP client in the same service, i.e. an HTTP proxy. Do I use Akka or Play2-mini?

I created such a service in Finagle and would like to repeat the exercise with Akka and / or Play2-mini to see how it compares.

At a high level, what does architecture look like? How do these products fit together?

+6
source share
2 answers

I would say that Spray is your best bet. However, it cannot be used with Java. We use the play2-mini platform, but there are some problems. It is not clear how to connect it to Akka with Java, compared to Spray, which is completely built around the concept - when a request arrives, you get a "Request" message for the actor.

In Play, you must flip your own connection: Ie, inside the static request method (eye roles):

Timeout timeout = new Timeout(Duration.parse("20 seconds")); Future<Object> future = Patterns.ask(myActor, new ClientMessage(null), timeout); Promise<Object> sdf = Akka.asPromise(future); Promise<Result> r2 = sdf.map(new Function<Object, Result>() { @Override public Result apply(Object a) throws Throwable { val wsrm = (MyMessage)a; return ok((wsrm).val); // String value from message object } }); Result test2 = async(r2); return test2; 

It works well. And Play also uses AKKA on this system, so you can create your actor using the actor context.

Unfortunately, at present, the Play2-mini is not at all mini, it depends on the entire structure of the Play, which also causes more problems. Apparently, they are working on the release of bare bones, which AFAIK is going to involve in the game sharing Play in its modules, and I do not see this happening in the near future.

IMO, Spray is a much better choice. This fluency fits much better with AKKA, but unfortunately I have to use Java here, so I could not use it: https://github.com/spray/spray/issues/96

As for your question about http clients / services - AKKA does not have any HTTP capabilities, so you need to interact with the HTTP server, in this case play. You can use Async requests to keep the connection alive while your actors system asynchronously sends messages to your client client to asynchronously receive an HTTP response by sending the message back to the web service level, returning to playback.

Hope this confuses some confusion. I was also confused, until several days of research;) If there is anything else I can help clarify, please let me know - for the benefit of the community !;)

Spray can has async http client, but for us people stuck in Java lands there is also: https://github.com/sonatype/async-http-client , which you can use possibly with AKKA.

+3
source

Asking this question, I found this great post on the Akka official blog:

http://letitcrash.com/post/17888436664/a-sample-application-showcasing-play-mini-and-akka

+1
source

Source: https://habr.com/ru/post/910090/


All Articles