Spring Cloud Sleuth
程序员文章站
2022-06-12 15:25:01
...
zipkin-server-2.10.1-exec.jar 下载地址zipkin-server-2.10.1-exec.jar
命令运行
java -jar zipkin-server-2.10.1-exec.jar
访问地址:http://localhost:9411/zipkin/
spring-cloud-sleuth-provider
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
application.yml
server:
port: 6818
spring:
application:
name: spring-cloud-sleuth-provider
zipkin:
base-url: http://127.0.0.1:9411/
###全部采集
# 默认是0.1 抽样采集,修改为1.0 为全部采集,但是影响接口使用效率
sleuth:
sampler:
probability: 1.0
eureka:
client:
serviceUrl:
defaultZone: http://localhost:6888/eureka/
SpringCloudSleuthProviderApplication.java
package com.mingshine.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringCloudSleuthProviderApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudSleuthProviderApplication.class, args);
}
}
TestController.java
package com.mingshine.cloud;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.UUID;
@RestController
public class TestController {
@Value("${server.port}")
private String serverPort;
@RequestMapping("/test")
public String test() {
return "spring-cloud-sleuth-provider: test========" + serverPort + "\t" + UUID.randomUUID().toString();
}
}
spring-cloud-sleuth-consumer
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
application.yml
server:
port: 6819
spring:
application:
name: spring-cloud-sleuth-consumer
zipkin:
base-url: http://127.0.0.1:9411/
sleuth:
sampler:
probability: 1.0
eureka:
client:
serviceUrl:
defaultZone: http://localhost:6888/eureka/
ApplicationContextConfig.java
package com.mingshine.cloud;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class ApplicationContextConfig {
@Bean
@LoadBalanced
public RestTemplate getTemplate(){
return new RestTemplate();
}
}
SpringCloudSleuthConsumerApplication.java
package com.mingshine.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringCloudSleuthConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudSleuthConsumerApplication.class, args);
}
}
TestController.java
package com.mingshine.cloud;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
@RestController
public class TestController {
private static final String INVOKE_URL = "http://spring-cloud-sleuth-provider";
@Resource
private RestTemplate restTemplate;
@GetMapping(value = "/test")
public String test(){
String result = restTemplate.getForObject(INVOKE_URL + "/test", String.class);
return result;
}
}
上一篇: 十、SpringCloud学习笔记之hystrix服务降级
下一篇: 双端队列广度优先搜索
推荐阅读
-
spring声明式事务学习笔记
-
Windows Azure NotificationHub+Firebase Cloud Message 实现消息推动(付源码)
-
一篇教你看懂spring bean工厂和aop
-
面试阿里被“吊打”,一问Spring三不知,半年后二战终拿下offer
-
Marketing Cloud demo环境和API使用方法说明 Marketing CloudSAP成都研究院SAP Cloud Platform云
-
关于Spring Cloud Eureka对服务的监控(上线,下线,续约等)
-
使用 Docker 部署 Spring Boot
-
Spring AOP的实现及源码解析
-
Springboot 系列(一)Spring Boot 入门篇
-
spring boot整合mybatis