Skip to content

Instantly share code, notes, and snippets.

@adleong
Created September 3, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adleong/80b24cf83847d690e2106e3b84f1c370 to your computer and use it in GitHub Desktop.
Save adleong/80b24cf83847d690e2106e3b84f1c370 to your computer and use it in GitHub Desktop.
simple scala client
/** Simple scala client */
import $ivy.`com.twitter::finagle-http:6.44.0`
import $ivy.`io.buoyant::finagle-h2:1.1.0`
import com.twitter.conversions.time._
import com.twitter.finagle.{Status => _, _}
import com.twitter.finagle.buoyant.h2._
import com.twitter.finagle.buoyant.H2
import com.twitter.io.Buf
import com.twitter.util._
import com.twitter.finagle.util.DefaultTimer
import com.twitter.logging._
@main
def main(host: String, port: Int) = {
Logger.configure(List(LoggerFactory(
node = "",
level = Some(Level.TRACE),
handlers = List(ConsoleHandler())
)))
implicit val timer = DefaultTimer.twitter
val client = H2.client.newClient(Name.bound(Address(host, port)), "client")
val service = Await.result(client())
for (i <- 1.to(10)) {
val s = Stream()
println("initiating request")
val req = Request("http", Method.Get, "foo", "/", s)
val rspF = service(req)
val rsp = Await.result(rspF)
println(rsp.status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment