一、下载、安装zipkin
zipkin的github地址:https://github.com/openzipkin/zipkin
下载:zipkin-server-2.11.5-exec.jar
执行:java -jar zipkin-server-2.11.5-exec.jar
访问地址:http://localhost:9411/zipkin/
二、在服务提供方、与消费方的pom.xml文件中添加依赖
<!--服务链路监控(包含sleuth、zipkin)-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
三、配置application.yml文件
spring:
application:
name: consumer-dept
zipkin:
base-url: http://localhost:9411 #zipkin地址
sleuth:
sampler:
percentage: 1 #抽样百分比(默认是0.1,即10%)-(只抽样监控10的请求%)
四、消费方发起请求,调用服务提供方的查询部门信息的接口
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.f6car.springcloud.entities.Dept;
@RestController
public class DeptController_Consumer {
private static final String REST_URL_PREFIX = "http://MICROSERVICECLOUD-DEPT";
@Autowired
private RestTemplate restTemplate;
@RequestMapping(value = "/consumer/dept/get/{