Created
September 25, 2014 11:50
-
-
Save akirillov/410d93bf51b830c05c4e to your computer and use it in GitHub Desktop.
Finagle Clietn Naive Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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