It seems that you already know the main difference between ask and tell , but do not understand how tell can be used to attract other participants in the processing of HTTP requests.
To make sense of using tell in HTTP request handlers, you must use an HTTP server that does not require request handlers to return their responses. Spray is such an HTTP server.
The request handler does not return a response to the spray; it is given a RequestContext object, and the response to the request involves calling some method on it. You can simply send this RequestContext to another player, who can then respond to the request:
path("foo") { rc => rc complete "foo" // respond here } ~ path("bar") { rc => barActor ! DoBar(rc) // send it to bar; NO RESPONSE HERE }
Then the actor referenced by barActor could say
case DoBar(rc) => rc complete "bar" // respond here, in another actor
The fact that Spray packs the request context into an object that can be passed and completed from any actor is great for the actor model. If, on the other hand, your web infrastructure requires the called handler to return a response, then if you want to attract another actor, your only choice is to use ask .
Typesafe has announced that Play will soon be using Spray below. Hopefully this means that Play then allow other members to send requests for processing.
Amigonico
source share