Thiago Pereira
Thiago Pereira

Reputation: 1712

Akka Http Client + Load Balancer

What is the correct way to fire a load-balancer using akka http? Currently I’m using the follow piece of code:

val poolClientFlow = Http().cachedHostConnectionPool[String](host, port)

source
  .map(url => HttpRequest(uri = url) -> url)
  .via(poolClientFlow)
  .to(Sink.actorRef(myActor, IsDone))
  .run()

Since I open the connection before, the load balancer understand I want to send to the same machine, so the roundrobin does not work properly. Should I move the poolClientFlow to the .via, open and closing it every time?

Upvotes: 3

Views: 736

Answers (1)

Age Mooij
Age Mooij

Reputation: 824

I wrote one a few weeks back as an experiment:

https://github.com/agemooij/stream-experiments/blob/master/src/main/scala/scalapenos/experiments/streams/LoadBalancingHttpClient.scala

It uses the graph DSL to balance the request over a number of separate connection pools.

Upvotes: 2

Related Questions