Search in sources :

Example 1 with HttpRequestWriter

use of com.linecorp.armeria.common.HttpRequestWriter in project zipkin by openzipkin.

the class HttpCall method sendRequest.

CompletableFuture<AggregatedHttpResponse> sendRequest() {
    final HttpResponse response;
    try (SafeCloseable ignored = Clients.withContextCustomizer(ctx -> ctx.logBuilder().name(name))) {
        HttpRequestWriter httpRequest = HttpRequest.streaming(request.headers());
        response = httpClient.execute(httpRequest);
        request.writeBody(httpRequest::tryWrite);
        httpRequest.close();
    }
    CompletableFuture<AggregatedHttpResponse> responseFuture = RequestContext.mapCurrent(ctx -> response.aggregateWithPooledObjects(ctx.eventLoop(), ctx.alloc()), // This should never be used in practice since the module runs in an Armeria server.
    response::aggregate);
    responseFuture = responseFuture.exceptionally(t -> {
        if (t instanceof UnprocessedRequestException) {
            Throwable cause = t.getCause();
            // Go ahead and reduce the output in logs since this is usually a configuration or
            // infrastructure issue and the Armeria stack trace won't help debugging that.
            Exceptions.clearTrace(cause);
            String message = cause.getMessage();
            if (message == null)
                message = cause.getClass().getSimpleName();
            throw new RejectedExecutionException(message, cause);
        } else {
            Exceptions.throwUnsafely(t);
        }
        return null;
    });
    this.responseFuture = responseFuture;
    return responseFuture;
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) OBJECT_MAPPER(zipkin2.elasticsearch.internal.JsonSerializers.OBJECT_MAPPER) RequestHeaders(com.linecorp.armeria.common.RequestHeaders) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HttpStatus(com.linecorp.armeria.common.HttpStatus) WebClient(com.linecorp.armeria.client.WebClient) Clients(com.linecorp.armeria.client.Clients) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Callback(zipkin2.Callback) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) Exceptions(com.linecorp.armeria.common.util.Exceptions) UnprocessedRequestException(com.linecorp.armeria.client.UnprocessedRequestException) SafeCloseable(com.linecorp.armeria.common.util.SafeCloseable) HttpData(com.linecorp.armeria.common.HttpData) HttpResponse(com.linecorp.armeria.common.HttpResponse) JsonParser(com.fasterxml.jackson.core.JsonParser) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) HttpStatusClass(com.linecorp.armeria.common.HttpStatusClass) RequestContext(com.linecorp.armeria.common.RequestContext) HttpRequest(com.linecorp.armeria.common.HttpRequest) HttpHeaders(com.linecorp.armeria.common.HttpHeaders) JSON_FACTORY(zipkin2.elasticsearch.internal.JsonSerializers.JSON_FACTORY) Call(zipkin2.Call) InputStream(java.io.InputStream) UnprocessedRequestException(com.linecorp.armeria.client.UnprocessedRequestException) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SafeCloseable(com.linecorp.armeria.common.util.SafeCloseable) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with HttpRequestWriter

use of com.linecorp.armeria.common.HttpRequestWriter in project zipkin by openzipkin.

the class BulkRequestBenchmarks method buildAndWriteRequest_singleSpan.

@Benchmark
public HttpRequest buildAndWriteRequest_singleSpan() {
    BulkCallBuilder builder = new BulkCallBuilder(es, V6_0, "index-span");
    builder.index(spanIndex, "span", CLIENT_SPAN, BulkIndexWriter.SPAN);
    HttpCall.RequestSupplier supplier = builder.build().request;
    HttpRequestWriter request = HttpRequest.streaming(supplier.headers());
    supplier.writeBody(request::tryWrite);
    return request;
}
Also used : HttpCall(zipkin2.elasticsearch.internal.client.HttpCall) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with HttpRequestWriter

use of com.linecorp.armeria.common.HttpRequestWriter in project zipkin by openzipkin.

the class BulkRequestBenchmarks method buildAndWriteRequest_tenSpans.

@Benchmark
public HttpRequest buildAndWriteRequest_tenSpans() {
    BulkCallBuilder builder = new BulkCallBuilder(es, V6_0, "index-span");
    for (int i = 0; i < 10; i++) {
        builder.index(spanIndex, "span", CLIENT_SPAN, BulkIndexWriter.SPAN);
    }
    HttpCall.RequestSupplier supplier = builder.build().request;
    HttpRequestWriter request = HttpRequest.streaming(supplier.headers());
    supplier.writeBody(request::tryWrite);
    return request;
}
Also used : HttpCall(zipkin2.elasticsearch.internal.client.HttpCall) HttpRequestWriter(com.linecorp.armeria.common.HttpRequestWriter) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

HttpRequestWriter (com.linecorp.armeria.common.HttpRequestWriter)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 HttpCall (zipkin2.elasticsearch.internal.client.HttpCall)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Clients (com.linecorp.armeria.client.Clients)1 UnprocessedRequestException (com.linecorp.armeria.client.UnprocessedRequestException)1 WebClient (com.linecorp.armeria.client.WebClient)1 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)1 AggregatedHttpResponse (com.linecorp.armeria.common.AggregatedHttpResponse)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpHeaders (com.linecorp.armeria.common.HttpHeaders)1 HttpRequest (com.linecorp.armeria.common.HttpRequest)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 HttpStatus (com.linecorp.armeria.common.HttpStatus)1 HttpStatusClass (com.linecorp.armeria.common.HttpStatusClass)1 RequestContext (com.linecorp.armeria.common.RequestContext)1 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)1 Exceptions (com.linecorp.armeria.common.util.Exceptions)1 SafeCloseable (com.linecorp.armeria.common.util.SafeCloseable)1