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
/** | |
* This is not meant to cover ALL possible ways of creating service clients; instead it focuses on the simplest way to | |
* do so, while maintaining the capability to customize the clients based on service level agreements/expectations | |
* | |
* @note Most of the filters can be applied to the HTTP client as well but have been omitted from the sample code to improve | |
* readability | |
*/ | |
trait ClientSamples extends LazyLogging { | |
private[this] lazy val config = ConfigFactory.load() |
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
import shapeless._ | |
object CaseClassMergeDemo extends App { | |
import mergeSyntax._ | |
case class Foo(i: Int, s: String, b: Boolean) | |
case class Bar(b: Boolean, s: String) | |
val foo = Foo(23, "foo", true) | |
val bar = Bar(false, "bar") |
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
class ThriftOverHttp extends Filter[ThriftClientRequest, Array[Byte], HttpRequest, HttpResponse] { | |
def apply(request: ThriftClientRequest, service: Service[HttpRequest, HttpResponse]) = { | |
val httpRequest = convertThriftRequestToHttpRequest(request) | |
val response = service(httpRequest) | |
response flatMap { res => | |
Future.value(res.getContent().array()) | |
} | |
} | |
private def convertThriftRequestToHttpRequest(request: ThriftClientRequest) = { |
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
var _ = require('underscore'), | |
util = require('util'); | |
// intercept stdout, passes thru callback | |
// also pass console.error thru stdout so it goes to callback too | |
// (stdout.write and stderr.write are both refs to the same stream.write function) | |
// returns an unhook() function, call when done intercepting | |
module.exports = function interceptStdout(callback) { | |
var old_stdout_write = process.stdout.write, | |
old_console_error = console.error; |