《zipkin》二 zipkin初体验

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43928720/article/details/101694778

1、下载

下载地址:https://search.maven.org/remote_content?g=io.zipkin.java&a=zipkin-server&v=LATEST&c=exec

2、运行

java -jar zipkin-server-2.12.9-exec.jar
在这里插入图片描述

3、访问

zipkin Server 运行后默认的访问地址:http://localhost:9411
在这里插入图片描述

4、调用链分析

启动4个服务,调用关系如下:brave-webmvc-example服务调用brave-webmvc-example2,brave-webmvc-example2分别调用brave-webmvc-example3和brave-webmvc-example4,
其中,这4个服务的接口如下:

(1)brave-webmvc-example中的start接口

@RequestMapping("start")
public String start(HttpServletRequest request1,HttpServletResponse response1) throws Exception, IOException {

   logger.info("start");
   //db();

   String data = restTemplate.getForObject("http://localhost:9090/foo", String.class);

   return data;
}

(2)brave-webmvc-example2中的foo接口

@RequestMapping("foo")
public String foo() throws InterruptedException, IOException {
   
   String data  = restTemplate.getForObject("http://localhost:9091/bar", String.class);
   String data2 = restTemplate.getForObject("http://localhost:9092/tar", String.class);
    logger.info("foo");

   return data+data2;
}

(3)brave-webmvc-example3中的bar接口

@RequestMapping("bar")
public String bar() throws InterruptedException, IOException {  //service3 method
    Random random = new Random();
    int sleep= random.nextInt(100);
    TimeUnit.MILLISECONDS.sleep(sleep);
    logger.info("bar");
    return " [service3 sleep " + sleep+" ms]";
}

(4)brave-webmvc-example4中的tar接口

 @RequestMapping("tar")
public String tar() throws InterruptedException, IOException { 
      logger.info("tar");
        Random random = new Random();
        int sleep= random.nextInt(1000);
        TimeUnit.MILLISECONDS.sleep(sleep);
        return " [service4 sleep " + sleep+" ms]";
}

访问brave-webmvc-example的start接口,即可开启这个调用链,返回结果如下:
在这里插入图片描述
然后访问zipkin服务器, 链路关系如下图:

在这里插入图片描述
链路调用详细信息如下图:
在这里插入图片描述
下期我们一起来探索一下zipkin的实现原理。

猜你喜欢

转载自blog.csdn.net/weixin_43928720/article/details/101694778