Spring Cloud Sleuth 整合

  引入Maven依赖

  org.springframework.cloud

  spring-cloud-starter-sleuth

  日志发生的变化

  当应用ClassPath下存在org.springfreamwork.cloud:spring-cloud-starter-sleuth的时候,日志会发生调整。

  激活

  @SpringBootApplication

  public class SpringCloudSleuthDemoApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudSleuthDemoApplication.class, args);

  }

  }

  Zipkin整合

  创建 Spring Cloud Zipkin服务器

  增加Maven依赖

  io.zipkin.java

  zipkin-server

  2.11.11

  io.zipkin.java

  zipkin-autoconfigure-ui

  2.11.11

  激活Zipkin服务器

  @SpringBootApplication

  @EnableZipkinServer

  public class SpringCloudZipkinDemoApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudZipkinDemoApplication.class, args);

  }

  }

  HTTP 收集 (HTTP调用)

  简单整合spring-cloud-sleuth

  增加Maven依赖

  org.springframework.cloud

  spring-cloud-starter-zipkin

  Spring Cloud 服务整合

  端口信息

  spring-cloud-zuul:7070

  person-client:8080

  person-service:9090

  Eureka Server:12345

  ZipKin Server:23456

  Config Server:10001

  服务启动顺序

  zipkin Server

  Eureka Server

  spring-cloud-config-server

  person-server

  person-client

  spring-cloud-zuul

  spring-cloud-sleuth

  spring-cloud-sleuth-demo改造

  增加Eureka客户端依赖

  org.springframework.cloud

  spring-cloud-starter-netflix-eureka-client

  配置调整

  spring.application.name = spring-cloud-sleuth

  server.port = 6060

  spring.zipkin.base-url=http://localhost:23456/

  eureka.client.serviceUrl.defaultZone=http://localhost:12345/eureka

  调整代码链接:spring-cloud-zuul

  完整调用链路

  spring-cloud-sleuth → spring-cloud-zuul → person-client → person-service

  @RestController

  public class TestLoggerController {

  final static Logger LOGGER = LoggerFactory.getLogger(TestLoggerController.class);

  @Autowired

  @Qualifier("restTemplate")

  private RestTemplate restTemplate;

  @GetMapping("/send")

  public void send() {

  LOGGER.info(" 欢迎欢迎!");

  }

  @GetMapping("/to/zuul/pseron-clint/findall")

  public Object findall() {

  LOGGER.info("TestLoggerController#findall()");

  return restTemplate.getForObject("http://spring-cloud-zuul/person-client/person/findall", Object.class);

  }

  }

  spring-cloud-zuul上报Zipkin服务器

  依赖无锡人流医院哪家好 http://www.bhnnkyy120.com/

  org.springframework.cloud

  spring-cloud-starter-zipkin

  配置

  spring.zipkin.base-url=http://localhost:23456/

  person-client上报Zipkin服务器

  依赖

  org.springframework.cloud

  spring-cloud-starter-zipkin

  配置

  spring.zipkin.base-url=http://localhost:23456/

  person-service上报Zipkin服务器

  依赖

  org.springframework.cloud

  spring-cloud-starter-zipkin

  配置

  spring.zipkin.base-url=http://localhost:23456/

  Spring Cloud Stream 收集消息(消息)

  调整spring-cloud-zipkin-server 通过Steam来收集

  增加Maven依赖

  org.springframework.cloud

  spring-cloud-sleuth-zipkin-stream

  org.springframework.cloud

  spring-cloud-stream-binder-kafka

  激活Zipkin Stream

  @SpringBootApplication

  //@EnableZipkinServer

  @EnableZipkinStreamServer

  public class SpringCloudZipkinDemoApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudZipkinDemoApplication.class, args);

  }

  }

  调整spring-cloud-zuul

  增加依赖

  org.springframework.cloud

  spring-cloud-sleuth-stream

  org.springframework.cloud

  spring-cloud-stream-binder-kafka

  org.springframework.cloud

  spring-cloud-starter-sleuth

  注释HTTP上报URL

  ##日志上报

  ##spring.zipkin.base-url=http://localhost:23456/

原文地址:https://www.cnblogs.com/djw12333/p/11475555.html