Skip to content

Instantly share code, notes, and snippets.

@akirillov
Created September 25, 2014 11:50
Show Gist options
  • Save akirillov/410d93bf51b830c05c4e to your computer and use it in GitHub Desktop.
Save akirillov/410d93bf51b830c05c4e to your computer and use it in GitHub Desktop.
Finagle Clietn Naive Example
def send[T <: WebLogEvent](event: T) = {
val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
.codec(Http())
.hosts(servers.mkString(","))
.hostConnectionLimit(10)
.retries(3)
.build()
val request = createFlumeRequest(event)
val future = client(request)
future onSuccess { result =>
result.getStatus match {
case HttpResponseStatus.OK => logger.debug(s"Event $event accepted by Flume")
case _ => logger.warn(s"Event haven't been accepted, response: $result")
}
} onFailure {
case f: FailFastException => logger.debug("FailFastException occurred:", f)
case e: Throwable => e.printStackTrace()
} ensure {
client.close()
}
future.toJavaFuture
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment