[Bot] [Relay] [Client]
| | .
|--ws:connect-->| .
| |<--HTTP/POST (Cmd)--|
|<--- (Cmd) ----| |
|---- (Resp) -->| |
[ if duration<delay]
| |------ (Resp) ----->|
[ else ]
| |--HTTP/PUT (Resp)-->|
[ /if ]
path("test") {
(post & entity(as[Command])) { (ctx, cmd) =>
serve(ctx, cmd) // Produce a Relay actor for `ctx` and `? cmd` to it
}
}
Hi! :)
On May 31, 2016 1:09 PM, "User 48" <gerv...@gmail.com> wrote:
>
> I there,
>
> I would like to create a service who acts as a relay between plain Http POST and WebSocket. The idea is to have this service who forward any POST requests body to a Websocket channel and use the Websocket response as Http response or send it to another server if the Websocket response arrive after a given delay.
>
>
> [Bot] [Relay] [Client]
> | | .
> |--ws:connect-->| .
> | |<--HTTP/POST (Cmd)--|
> |<--- (Cmd) ----| |
> |---- (Resp) -->| |
> [ if duration<delay]
> | |------ (Resp) ----->|
> [ else ]
> | |--HTTP/PUT (Resp)-->|
> [ /if ]
>
> Command handling sequence diagram
>
>
> It seems feasible but I would like to use Akka and being a beginner I have some questions :
>
> **1/** I can't find anything explaining how to create a Socket where I can write at any time.
This "unfortunately" doesn't exist. (Not as in Akka Http, but as in Reality)
Relying on such an assumption will lead to subtly (or not so subtly) broken systems.
What are the requirements, implementation aside?
> The Bot must be "always" connected so that the webscoket channel will be always opened. I have to write on it only when receiving an Http POST request. But in the samples it is a request-response flow.
See above.
>
> **2/** Each incoming Cmd must have his own actor to be linked to the orginal Client and decide if the response can be sent to the Http flow or must be send via a new Http/PUT if the delay is expired.
How do you identify the "original Client"?
> The actor-per-request pattern seems to be the perfect candidate. But I would like to create a Relay actor for each request and let this one handle the request and send the response (`RequestContext.complete`) but when doing that I cannot create the Route because I don't have any return type.
>
> path("test") {
> (post & entity(as[Command])) { (ctx, cmd) =>
> serve(ctx, cmd) // Produce a Relay actor for `ctx` and `? cmd` to it
> }
> }
Hmmm, does this section of the documentation help?
http://doc.akka.io/docs/akka/2.4.6/scala/http/routing-dsl/index.html
>
>
> The NET-A-PORTER sample is using Spray which seems to allow direct use of actors as route element but I cannot find the equivalent for Akka-http.
>
>
> Can someone help me or point me to the documentation part ?
>
> Thanks a lot
I hope I was of *some* help,
let the group know if you made progress!
Cheers,
√
>
>
>
>
> (this question was originally posted on StackOverflow : http://stackoverflow.com/questions/37524001/akka-websocket-emit-to-stream-and-produce-one-actor-per-request)
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
> To post to this group, send email to akka...@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
Result send(final Command command) {
write(command);
wait();
return this.result;
}
void onWebSocketText(String message) {
this.result = parse(message);
notify();
}