spring cloud sleuth zipkin http收集


spring cloud sleuth zipkin http收集

*********************************

启动 zipkin-server

docker run -it -d --net fixed3 --ip 192.168.57.2 -e "QUERY_PORT=8080" --name zipkin openzipkin/zipkin

说明:使用http收集、内存存储,自定义端口8080

*********************************

服务1:hello-service

*********************

配置文件

spring:
  application:
    name: hello-service
  cloud:
    consul:
      host: 192.168.57.21
      port: 8500
  zipkin:
    base-url: http://192.168.57.2:8080

*********************

controller 层

HelloController

@RestController
public class HelloController {

    private Logger logger= LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/hello")
    public String hello(){
        logger.info("hello controller:{}","hello world");

        return "hello world";
    }
}

*********************************

服务2:hello-consumer

*********************

配置文件

spring:
  application:
    name: hello-consumer
  cloud:
    consul:
      host: 192.168.57.21
      port: 8500
  zipkin:
    base-url: http://192.168.57.2:8080

*********************

service 层

HelloService

@FeignClient(name = "hello-service",fallback = HelloServiceImpl.class)
public interface HelloService {

    @RequestMapping("/hello")
    String hello();
}

*********************

serviceImpl 层

HelloServiceImpl

@Service
public class HelloServiceImpl implements HelloService {

    @Override
    public String hello() {
        return "本地输出:"+"hello world";
    }
}

*********************

controller 层

HelloConsumerController

@RestController
public class HelloConsumerController {

    private Logger logger= LoggerFactory.getLogger(HelloConsumerController.class);

    @Resource
    private HelloService helloService;

    @RequestMapping("/consume")
    public String consume(){
        logger.info("调用 hello-service:{}",helloService.hello());
        logger.info("本地输出:{}","hello consumer controller");

        return "hello consumer";
    }
}

***************************

使用测试

调用/consume接口

      

      

再次调用/consume接口

      

说明:再次调用接口,出现两条该日志记录

发布了387 篇原创文章 · 获赞 98 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43931625/article/details/104844911