Spring Cloud learning (seven) Spring Cloud Sleuth

Micro-service architecture is a distributed architecture, micro-service system by business services unit, a micro-service systems tend to have a number of service units. Due to the large number of service units, the higher the complexity of the business, if something goes wrong and abnormal, it is difficult to locate. Mainly in a request you may need to call a number of services, internal services and call complexity of the problem difficult to locate. So in the micro-service architecture, we must implement a distributed link tracking, to follow up a request in the end what services involved in order to participate and how to achieve the steps each request is clearly visible, a problem can quickly locate the purpose of
the common link tracking component has Google's Dapper, Twitter's Zipkin, and Ali Eagleeye (Hawkeye)

concept

  1. Span: the basic unit of work, transmitting a scheduled task will generate a remote Span. It contains a summary of the event timestamp, Span's ID and process ID
  2. Trace: Span composed of a series, showing a tree structure. A micro system service request API interface, the interface need to call the API service a plurality of micro cells, each micro-call service unit will generate a new Span, Span all generated by this request of this composition Trace
  3. Annotation: used to record an event, some of the core annotation is used to define the start and end of a request, these notes are as follows:
    1. cs-Client Sent: The client sends a request, the note describes the beginning of Span
    2. sr-Server Received: server request and get ready to deal with it, with sr cs minus timestamp, you can get the network transmission time
    3. ss-Server Sent: the server sends a response, which notes that the request to complete the process (when the request back to the client), minus the time stamp with a time stamp sr ss, they can get the server request time
    4. er-Client Received: The client receives the response, the time from the end of Span, minus the timestamp time stamp cs er, they can be consumed by the time the entire request

      Zipkin Server

      Download Zipkin Server
      start Zipkin Server:
      java -jar zipkin-server-2.12.9-exec.jar
      
      Zipkin Server default port is 9411
      in more detail on Zipkin Reference: https://zipkin.io/pages/quickstart.html

      eureka-client

      Add dependent

      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-zipkin</artifactId>
      </dependency>
      

      Add application.yml

      spring:
      zipkin:
      base-url: http://localhost:9411 # Zipkin Server 地址
      sleuth:
      sampler:
      probability: 1.0 # 以 100% 的概率将链路的数据上传给 Zipkin Server
      

      zuul-client

      Step with eureka-client

      test

  4. Start eureka-server
  5. Start config-server
  6. Start eureka-client
  7. Start zuul-client
    access http: // localhost: 8051 / hiapi
    / hi name = victor & token = xx? Visit http: // localhost: 9411 / zipkin Click [Find] button to see the link information

The complete code: GitHub
own Java C # turn the newbie, please correct me if wrong or insufficient, thank you

Guess you like

Origin www.cnblogs.com/victorbu/p/11026717.html