Hi Magnus,


On Wed, Dec 24, 2014 at 1:55 AM, Magnus Andersson <
[email protected]> wrote:

> Hi
>
> I am building a simple reverse proxy as an exercise to understand Akka
> Streams. I have read the new docs but could not find an answer.
>
> I'm using FlexiRoute as recommended in an earlier thread to determine when
> my Akka HTTP service should proxy to the remote service and when not to.
> But even if the flow does not go through the reverse proxy part of the
> graph, I still see a remote connection established in the logs. This
> happens every single time, regardless of input request.
>

Yes, all Flows are materialized when you materialize the container graph.
Flows representing connections do the actual connect when you materialize
them.


>
> How do I avoid this behaviour?
>

The "connect-when-materialized" is by design.


> I only want the connection to be established when that part of the graph
> flow is executed.
>

Your problem of timed out connections will happen anyway even though a
first message was sent through, after not receiving a new message for a
while. If I assume that proxyBranch is using HttpClient then I guess we are
talking about functionality that is not there yet (pooled connections a la
Spray), the current API as far as I know is just using a single TCP
connection.

Alternatively you can use "mapAsync{ req =>
Source.single(req).via(Http().outgoing.flow).runWith(Sink.head) }" which
edge will materialize a new outgoing proxy flow for each request instead of
reusing a statically materialized flow. Probably a bit less efficient, but
will avoid your problems.

-Endre


>
> This is the flow graph setup:
>
>     val partialBranch = PartialFlowGraph {
>       implicit b ⇒
>         import FlowGraphImplicits._
>         val route = new BranchRoute[HttpRequest]
>         val merge = MergePreferred[HttpResponse]
>         in ~> proxyBranch ~> route.in
>         route.success ~> proxyTo ~> con ~> merge
>         route.failure ~> badRequestFlow ~> merge.preferred
>         merge ~> out
>     }
>
>
> Please see this gist for a fully working example:
> https://gist.github.com/magnusart/bffe1a15dab30f794235
>
> Oh, and merry christmas! :)
>
> /Magnus
>
>
> --
> >>>>>>>>>> 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