Spring Cloud Learning Notes-012

Source: Internet
Author: User
Tags joins

    • Distributed Service tracking: Spring Cloud Sleuth

With the development of the business, the scale of the system will become bigger and larger, and the call relationship between the microservices becomes more and more complex. Typically a client-initiated request will be used by several different microservices calls in the backend system to produce the final request result, and in a complex microservices architecture system, almost every front-end request forms a complex distributed service invocation link, It is possible to cause the final failure of the request in the event of a high or false delay in any dependent service on each link. At this point, the tracking of full-link calls becomes more and more important for each request, and by implementing a trace of the request invocation can help us quickly identify the source of the error and monitor the performance bottlenecks on each request link.

1. Preparatory work to build some basic facilities and applications:

   Service Registration Center: demo-eureka-server, do not repeat here, directly using the construction of the previous project can be.

microservices Application: demo-trace-1, implements a rest interface/trace-1, which triggers a call to the Trace-2 app when the interface is called. Specific as follows :

1). Create a basic Sprigboot application named Demo-trace-1, which joins the Web, Eureka, and ribbon dependencies.

2). Create the application main class:


3). Create the Application.yml file in the Src\main\resources directory:


4). Create a basic Sprigboot application named Demo-trace-2, which joins the Web, Eureka, and ribbon dependencies.

5). Create the application main class:


6). Create the Application.yml file in the Src\main\resources directory:


7). Start up the Demo-eureka-server, demo-trace-1, and demo-trace-2 three applications. Test the Trace-1 interface to verify that the error is returned:


2. After you have completed the preparation, add the service tracking feature for the trace-1 and trace-2 above. Add dependent dependencies in the Pom.xml file for trace-1 and trace-2:

3. Restart Trace-1 and trace-2, call the Trace-1 interface again, observe the trace-1 console, and some log information, which is an important part of implementing distributed Service tracking:

    • Integration with Zipkin

Zipkin is an open source project for Twitter, based on Google Dapper. It can be used to collect trace data on the request link on each server, and through its Rest API interface to assist the query tracking data to implement the monitoring program of the distributed system, so as to detect the delay rise problem in the system and find out the root of the system performance bottleneck. In addition to the development-oriented API interface, it also provides a handy UI component to help us visually search for trace information and analyze request link details, such as querying the processing time of each user request over a certain period of time.

Zipkin the main 4 core components:

   Collector: collector component, which mainly handles tracking information sent from external systems, translates this information into a zipkin internal processing span format to support subsequent storage, analysis, and presentation functions.

   Storage: A storage component that primarily handles the trace information received by the collector, which is stored in memory by default. You can also modify this storage policy to store trace information in the database by using other storage components.

   RESTful API: API component, which is used primarily to provide external access interfaces. For example, to show the client job information, or external system access for monitoring and so on.

   Web UI: UI component, an upper-level application based on API component implementation. Through the UI components, users can easily and intuitively query and analyze trace information.

1. Create Maven project, skeleton Select QuickStart, named Demo-zipkin-server

2. Join related dependencies:

3. Create a Startup class:

4. Create the Application.properties file in the Src\main\resources directory:

5. Start the project (Note: JDK1.8 required) and visit the main page:

6. Trace-1 and Trace-2 works prior to transformation. Dependencies are added to both projects:

7. Add configuration information for Zipkin server in the configuration files for both projects:

8. Restart the two projects and visit the Trace-1 interface to observe the Zipkin page:

Spring Cloud Learning Notes-012

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.