Thanks for the response. This is somewhat encouraging. +1 to cookbook and
migration docs.

I'm not up to speed on Flows, so I don't know what the proposed solution
would look like in a route definition.
In the meantime (this is just for a new proof of concept app) I embraced
the Ask in the route definition and create one-offs in response. I didn't
use forwarding as Patrik mentioned. Instead the one-off has a "requester"
property and after doing a bunch of tells and receives, completes the ask
future by sending a response to the requester. I hope this is OK - it seems
to work as a bridge between AskWorld and TellDon'tAskWorld.

On Wed, Sep 9, 2015 at 3:34 AM, Akka Team <[email protected]> wrote:

>
>
> On Wed, Sep 9, 2015 at 12:27 PM, Patrik Nordwall <
> [email protected]> wrote:
>
>>
>>
>> On Wed, Sep 9, 2015 at 12:05 PM, Akka Team <[email protected]>
>> wrote:
>>
>>>
>>>
>>> On Wed, Sep 9, 2015 at 11:59 AM, Patrik Nordwall <
>>> [email protected]> wrote:
>>>
>>>>
>>>>
>>>> On Wed, Sep 9, 2015 at 11:17 AM, Akka Team <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Richard,
>>>>>
>>>>> There is no easy way currently to do per-request actors (except that
>>>>> everything in your handler Flow is kind of a per-request actor), this is
>>>>> something we need to improve. I created an issue:
>>>>> https://github.com/akka/akka/issues/18431
>>>>>
>>>>
>>>> It's possible to create an actor from the mapAsync function and return
>>>> the Future of an ask request to that new actor. What am I missing?
>>>> /Patrik
>>>>
>>>
>>> Where would you create the actor? You need an ActorRefFactory for that,
>>> and the only legal way from inside a stage would be then to create a
>>> top-level actor, which is far from optimal.
>>>
>>
>> I could have created a top level actor up front and let that one create
>> child actors on demand. The ask would go to the top level actor that
>> forwards to a child. It could be a router if a single top level actor
>> becomes a bottleneck.
>>
>
> That can work, even if not trivial. Also ties the Flow to a certain
> top-level actor, making it less reusable -- but it might not matter in an
> Http handler anyway. I just still don't like that single bottleneck point,
> router or not.
>
>
>>
>> I agree that this is a nice feature to have built-in, but I think there
>> are ways that are rather alright already.
>>
>
> If nothing else, we should make this a cookbook pattern. Btw there is no
> HTTP cookbook yet.
>
> -Endre
>
>
>>
>>
>>>
>>> -Endre
>>>
>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> -Endre
>>>>>
>>>>> On Mon, Sep 7, 2015 at 7:23 PM, Richard Rodseth <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> I've run into the same problem. How to do per-request actors rather
>>>>>> than ask pattern with Akka Http, and I'm afraid I don't understand how
>>>>>> handlerFlow helps. I've started a separate thread, but if either of you 
>>>>>> can
>>>>>> elaborate that would be great. The Spray migration page is still marked
>>>>>> TODO.
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> On Tue, Jun 16, 2015 at 7:00 PM, Nicolau Werneck <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Great, thanks for the reply!    ++nic
>>>>>>>
>>>>>>>
>>>>>>> On Tuesday, June 16, 2015 at 5:40:55 AM UTC-3, Richard Bradley wrote:
>>>>>>>>
>>>>>>>> You can see the source code to the net-a-porter Spray example here:
>>>>>>>>
>>>>>>>> https://github.com/NET-A-PORTER/spray-actor-per-request/blob/master/src/main/scala/com/netaporter/Boot.scala
>>>>>>>>
>>>>>>>> The startup looks like:
>>>>>>>>   IO(Http) ! Http.Bind(serviceActor, "localhost", port = 38080)
>>>>>>>>
>>>>>>>> where "serviceActor" is an actor that mixes in
>>>>>>>> spray.routing.HttpService, as you say. The actor uses that trait to 
>>>>>>>> call
>>>>>>>> "runRoute" to bind its Route to the HTTP layer.
>>>>>>>>
>>>>>>>>
>>>>>>>> In Akka HTTP, you instead need to wrap a Route with
>>>>>>>> "akka.http.scaladsl.server.Route.handlerFlow" to turn it into a
>>>>>>>> Flow[HttpRequest, HttpResponse, Unit] and then pass that into
>>>>>>>> "Http().bindAndHandle(...)".
>>>>>>>> See
>>>>>>>> http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M5/scala/http/server.html
>>>>>>>> for more on the new API.
>>>>>>>>
>>>>>>>> That part has changed quite a bit, but from the Routing layer on
>>>>>>>> down, everything is very much the same, in my opinion.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tuesday, June 16, 2015 at 4:41:54 AM UTC+1, Nicolau Werneck
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> All right then, except I'm under the impression that to use that
>>>>>>>>> pattern we need to create an application using the
>>>>>>>>> `spray.routing.HttpService` class, and I could not find it in 
>>>>>>>>> akka-http. Is
>>>>>>>>> it available under a different name?
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>     ++nic
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Monday, June 15, 2015 at 3:51:27 PM UTC-3, Richard Bradley
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> The situation is very much the same in Akka HTTP as it was in
>>>>>>>>>> Spray 1.3.
>>>>>>>>>> You should be able to translate the actor-per-request pattern
>>>>>>>>>> into Akka with only superficial changes.
>>>>>>>>>> If you didn't deal with large (streamed / chunked) requests,
>>>>>>>>>> everything is very much the same from Routing on down.
>>>>>>>>>>
>>>>>>>>>> As to which is recommended -- I think that is much the same as
>>>>>>>>>> well:
>>>>>>>>>>
>>>>>>>>>> Actor-per-request needs more book-keeping (to avoid leaks) but
>>>>>>>>>> allows greater control in complex scenarios.
>>>>>>>>>>
>>>>>>>>>> Future calls (which can include "asks" on Actors) are simpler and
>>>>>>>>>> usually more type-safe and easier to work with IMO. You need to be 
>>>>>>>>>> very
>>>>>>>>>> careful around mutable state though.
>>>>>>>>>>
>>>>>>>>>> HTH,
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Rich
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Monday, June 15, 2015 at 4:50:54 AM UTC+1, Nicolau Werneck
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> From what I gathered from the documentation and examples, the
>>>>>>>>>>> usual way to answer to a request asynchronously in Spray and 
>>>>>>>>>>> akka-http is
>>>>>>>>>>> to `complete` with a `Future`, which may be produced from asking an 
>>>>>>>>>>> actor.
>>>>>>>>>>> But in Spray there was also the so-called "actor per-request" 
>>>>>>>>>>> pattern,
>>>>>>>>>>> documented in
>>>>>>>>>>> http://techblog.net-a-porter.com/2013/12/ask-tell-and-per-request-actors/
>>>>>>>>>>>
>>>>>>>>>>> Is that still possible to do with akka-http? And is it
>>>>>>>>>>> discouraged in general? Should we really stick to using Futures to
>>>>>>>>>>> integrate akka-http to the rest of our applications?
>>>>>>>>>>>
>>>>>>>>>>>     ++nic
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>> >>>>>>>>>> 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 [email protected].
>>>>>>> To post to this group, send email to [email protected].
>>>>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> >>>>>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Akka Team
>>>>> Typesafe - Reactive apps on the JVM
>>>>> Blog: letitcrash.com
>>>>> Twitter: @akkateam
>>>>>
>>>>> --
>>>>> >>>>>>>>>> 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 [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Patrik Nordwall
>>>> Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
>>>> Twitter: @patriknw
>>>>
>>>> --
>>>> >>>>>>>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/akka-user.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> Akka Team
>>> Typesafe - Reactive apps on the JVM
>>> Blog: letitcrash.com
>>> Twitter: @akkateam
>>>
>>> --
>>> >>>>>>>>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>>
>> Patrik Nordwall
>> Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
>> Twitter: @patriknw
>>
>> --
>> >>>>>>>>>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Akka Team
> Typesafe - Reactive apps on the JVM
> Blog: letitcrash.com
> Twitter: @akkateam
>
> --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to