use of io.opencensus.contrib.http.jetty.client.OcJettyHttpClient in project instrumentation-java by census-instrumentation.
the class HelloWorldClient method main.
/**
* HelloWorldClient sends http request periodically to {@link HelloWorldServer}. These requests
* are instrumented using opencensus jetty client library to enable tracing and monitoring stats.
*/
public static void main(String[] args) throws Exception {
BasicConfigurator.configure();
initTracing();
initStatsExporter();
// Create http client that will trace requests. By default trace context is propagated using
// w3c TraceContext propagator.
// To use B3 propagation use following
// OcJettyHttpClient httpClient =
// new OcJettyHttpClient(
// new HttpClientTransportOverHTTP(),
// new SslContextFactory(),
// null,
// Tracing.getPropagationComponent().getB3Format());
OcJettyHttpClient httpClient = new OcJettyHttpClient(new HttpClientTransportOverHTTP(), new SslContextFactory(), null, null);
httpClient.start();
do {
HttpRequest request = (HttpRequest) httpClient.newRequest("http://localhost:8080/helloworld/request").method(HttpMethod.GET);
HttpRequest asyncRequest = (HttpRequest) httpClient.newRequest("http://localhost:8080/helloworld/request/async").method(HttpMethod.GET);
HttpRequest postRequest = (HttpRequest) httpClient.newRequest("http://localhost:8080/helloworld/request").method(HttpMethod.POST);
postRequest.content(new StringContentProvider("{\"hello\": \"world\"}"), "application/json");
if (request == null) {
logger.info("Request is null");
break;
}
request.send();
asyncRequest.send();
postRequest.send();
try {
Thread.sleep(15000);
} catch (Exception e) {
logger.error("Error while sleeping");
}
} while (true);
}
Aggregations