Skip to content

Instantly share code, notes, and snippets.

@ldaley
Forked from kramer/build.gradle
Created August 7, 2014 01:41
Show Gist options
  • Save ldaley/e5cdb22d9cf14118932c to your computer and use it in GitHub Desktop.
Save ldaley/e5cdb22d9cf14118932c to your computer and use it in GitHub Desktop.
buildscript {
repositories {
maven { url "http://oss.jfrog.org/repo" }
mavenCentral()
}
dependencies {
classpath 'io.ratpack:ratpack-gradle:0.9.7'
}
}
repositories {
maven { url "http://oss.jfrog.org/repo" }
mavenCentral()
maven { url "http://repo.springsource.org/repo" } // for springloaded
}
// The “ratpack” plugin applies the “application” plugin, making it easy to create a standalone application.
// See: http://gradle.org/docs/current/userguide/application_plugin.html
apply plugin: "io.ratpack.ratpack-groovy"
// The “ratpack” plugin is IDEA aware.
// It will create a run configuration in IDEA to launch your app in your IDE, with hot reloading.
apply plugin: "idea"
idea {
project {
jdkName "1.7"
languageLevel "1.7"
}
}
configurations.all {
exclude module: "groovy"
}
dependencies {
// SpringLoaded enables runtime hot reloading.
// It is not part of the app runtime and is not shipped in the distribution.
springloaded "org.springsource.springloaded:springloaded-core:1.1.4"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0", {
exclude module: "groovy-all"
}
compile 'io.ratpack:ratpack-rx:0.9.7'
compile 'com.ning:async-http-client:1.8.13'
}
import com.ning.http.client.AsyncHttpClient
import com.ning.http.client.AsyncHttpClientConfig
import ratpack.http.client.HttpClient
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
import static ratpack.groovy.Groovy.ratpack
import static ratpack.rx.RxRatpack.initialize
import static ratpack.rx.RxRatpack.observe
ratpack {
bindings {
initialize()
bind AsyncHttpClient.class, new AsyncHttpClient(
new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(30000).setRequestTimeoutInMs(30000).build()
)
}
handlers {
get("multi") { AsyncHttpClient client, HttpClient httpClient ->
// call "single" endpoint multiple times
def count = 0
rx.Observable.from((1..2000)).flatMap({
// [1]
// observe(httpClient.get {
// it.url.set(new URI("http://127.0.0.1:5050/single"))
// })
// [2]
// observe(promise { f ->
// client.prepareGet("http://127.0.0.1:5050/single").execute(new AsyncCompletionHandlerBase() {
// @Override
// Response onCompleted(Response response) throws Exception {
// f.success(response)
// response
// }
//
// @Override
// void onThrowable(Throwable t) {
// f.error(t)
// }
// })
// })
}).subscribe({
println count
count++
}, {
it.printStackTrace()
}, {
println "complete! - emitted $count times"
render "complete! - emitted $count times"
})
}
get("single") {
observe(blocking({
// simulate some blocking load
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
SecretKeySpec key = new SecretKeySpec("0123456789abcdef".bytes, "AES");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec("AAAAAAAAAAAAAAAA".bytes));
6400.times { cipher.update(it.byteValue()) }
cipher.doFinal("0123456789ABCDEF".bytes).toString()
})).subscribe({
println "ok $it"
render "ok $it"
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment