Copyright © since 1998 DMM All Rights Reserved. 32
ࠓճ"1*(BUFXBZαʔόʔͳͷͰIPTUDPOOFDUJPOQPPMΛ
༻ɻϗετຖͷϓʔϧ44-ͷઃఆBQQMJDBUJPODPOGɻ
Sample code of Akka HTTP client
trait HttpClients extends ActorSystemAware {
// Type parameter [T] means to keep path-through data in Flow’s I/O.
def forUri[T](apiUrl: Uri): Flow[(HttpRequest, T), (Try[HttpResponse], T), HostConnectionPool] = {
val host = apiUrl.authority.host.toString
val port = apiUrl.authority.port
val hostSettings = resolveHostSpecificSettings(host) | defaultConnectionPoolSettings
val sslCtxt = Global.clientHttpsContext | Http().defaultClientHttpsContext
(apiUrl.scheme, port) match {
case ("http" , 0) => Http().cachedHostConnectionPool[T](host, settings = hostSettings)
case ("http" , _) => Http().cachedHostConnectionPool[T](host, port, hostSettings)
case ("https", 0) => Http().cachedHostConnectionPoolHttps[T](host, connectionContext = sslCtxt
, settings = hostSettings)
case ("https", _) => Http().cachedHostConnectionPoolHttps[T](host, port, sslCtxt, hostSettings)
case _ => throw new NoSuchElementException
}
// .......
}
This time it is an API Gateway server, so we set up endpoints
host connection pool.
The number of connection pools and the setting of SSL for each
host is basically set in application.conf.