项目作者: mintutu

项目描述 :
The Scala HTTP client
高级语言: Scala
项目地址: git://github.com/mintutu/httpclient4s.git
创建时间: 2019-04-28T10:10:40Z
项目社区:https://github.com/mintutu/httpclient4s

开源协议:Apache License 2.0

下载


HTTP Client for Scala

Build Status
Codacy Badge

Introduction

Build on top Akka HTTP Client to support multiple hosts and different selector strategies and retry strategies

Making a Request

  1. implicit val system = ActorSystem()
  2. import system.dispatcher
  3. implicit val materializer = ActorMaterializer()
  4. val servers = Seq(Uri(s"http://192.168.0.100:8080"), Uri(s"http://192.168.0.101:8080"))
  5. val httpClient = new HttpMultipleHostPool(
  6. servers,
  7. bufferSize = 10,
  8. new InfiniteStrategy(),
  9. OverflowStrategy.dropBuffer
  10. ) with WeightedRoundRobinSelector {
  11. override val defaultWeight: Int = 100
  12. override val decrementBy: Int = 30
  13. }
  14. val response = httpClient.sendRequest(HttpRequest(uri = "/query"))
  15. val result = Await.result(response, 10 seconds)
  16. println(s"Get Response: $result")