Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created March 11, 2014 16:25
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 purplefox/9489311 to your computer and use it in GitHub Desktop.
Save purplefox/9489311 to your computer and use it in GitHub Desktop.
import org.vertx.java.core.Handler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpClientResponse;
import org.vertx.java.core.http.HttpClient;
import org.vertx.java.platform.Verticle;
public class ClientExample extends Verticle {
public void start() {
HttpClient client = vertx.createHttpClient().setPort(8080).setHost("localhost").setKeepAlive(false);
doGet(client, 0);
}
private void doGet(final HttpClient client, int count) {
System.out.println("Request: " + count);
final int cnt = count + 1;
client.getNow("/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse response) {
response.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer data) {
System.out.println(data);
vertx.setTimer(1, new Handler<Long>() {
public void handle(Long l) {
doGet(client, cnt);
}
});
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment