Spring Cloud搭建微服務架構----使用Zipkin作服務鏈路追蹤

實例主要有三個工程組成:java

  • Server-zipkin:經過ZipkinServer功能,實現收集調用數據,展現;
  • Service1:對外暴漏的服務接口;
  • Service2:對外暴漏的服務接口;

兩個服務能夠相互調用,服務相互調用以後能夠經過Service-Zipkin收集數據進行鏈路追蹤。git

Zipkin-Server

POM:github

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>io.zipkin.java</groupId>
			<artifactId>zipkin-server</artifactId>
		</dependency>
		<dependency>
			<groupId>io.zipkin.java</groupId>
			<artifactId>zipkin-autoconfigure-ui</artifactId>
		</dependency>
	</dependencies>

Service01,Service02

POM:web

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

properties:spring

spring.application.name=service-01
server.port=7001

spring.zipkin.base-url=http://localhost:9400  #zipkin地址

應用互相調用:api

@RequestMapping(value = "/api", method = RequestMethod.GET)
    public String api() {
        return restTemplate.getForEntity(
                "http://localhost:7002/hi",
                String.class).getBody();
    }

經過:http://10.168.12.25:9400/dependency 查看服務引用;springboot

代碼實例

https://github.com/zhangcj/easymall/tree/master/springbootdemo/springbootdemo-zipkinapp

相關文章
相關標籤/搜索