You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/12/11 16:19:10 UTC

[GitHub] [skywalking] haoyann edited a comment on issue #5653: http async client does not create span

haoyann edited a comment on issue #5653:
URL: https://github.com/apache/skywalking/issues/5653#issuecomment-743234438


   @jsankalp Don't close httpclient, second request you can see the bug. beacuse httpclient will cache the connection.
   ```
       private static final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
   
       static {
           httpclient.start();
       }
   
       @GetMapping("/httpasyncclient")
       public String front() throws Exception {
           return asyncRequest3("http://127.0.0.1:8089/httpasyncclient/back");
       }
   
       private String asyncRequest3(String url) throws IOException {
   
           final HttpGet request3 = new HttpGet(url);
           HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(request3);
           AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
               HttpResponse response;
   
               @Override
               protected void onResponseReceived(final HttpResponse response) {
                   this.response = response;
               }
   
               @Override
               protected void onCharReceived(final CharBuffer buf, final IOControl ioctrl) throws IOException {
               }
   
               @Override
               protected void releaseResources() {
               }
   
               @Override
               protected HttpResponse buildResult(final HttpContext context) {
                   return this.response;
               }
           };
   
           httpclient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
               public void completed(final HttpResponse response3) {
                   LOGGER.info(request3.getRequestLine() + "->" + response3.getStatusLine());
               }
   
               public void failed(final Exception ex) {
                   LOGGER.error(request3.getRequestLine() + "->" + ex);
               }
   
               public void cancelled() {
                   LOGGER.error(request3.getRequestLine() + " cancelled");
               }
   
           });
           return "Success";
       }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org