spring-cloud-sleuth+zipkin追踪服务
2024-09-05 07:32:10
1, 父Maven pom 文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 解决 JDK 9 以上没有 JAXB API 的问题 -->
<!-- <dependency>-->
<!-- <groupId>javax.xml.bind</groupId>-->
<!-- <artifactId>jaxb-api</artifactId>-->
<!-- <version>2.3.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.sun.xml.bind</groupId>-->
<!-- <artifactId>jaxb-impl</artifactId>-->
<!-- <version>2.3.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.sun.xml.bind</groupId>-->
<!-- <artifactId>jaxb-core</artifactId>-->
<!-- <version>2.3.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.activation</groupId>-->
<!-- <artifactId>activation</artifactId>-->
<!-- <version>1.1.1</version>-->
<!-- </dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2, Slueth Server 服务器
pom 文件
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<version>2.9.4</version>
</dependency>
</dependencies>
yml 文件
server:
port: 9090
启动类
@SpringBootApplication
@EnableZipkinServer
public class ZipKinServer {
public static void main(String[] args) {
SpringApplication.run(ZipKinServer.class,args);
}
}
-------------------------------------------------
zipkinclient 模块代码
@RestController
@RequestMapping("/zipkin")
public class ZipkinHandler {
@Value("${server.port}")
private String port;
@GetMapping("/index")
public String index(){
return this.port;
}
@RequestMapping("/get")
public String addItem( @RequestParam("desc") String desc){
return "this is zipkin client"+desc;
}
@RequestMapping("/geterro")
public String addI( @RequestParam("desc") String desc){
int m=0;
int n=100/m;
return "this is zipkin client error"+desc;
}
}
3, slueth client
pom 文件
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
yml 文件
server:
port: 8010
spring:
application:
name: common
sleuth:
web:
client:
enabled: true
sampler:
probability: 1.0
zipkin:
base-url: http://localhost:9090/
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
启动文件
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public class CommonApp {
public static void main(String[] args) {
SpringApplication.run(CommonApp.class,args);
}
}
----------------------------------------------
@FeignClient(value = "zipkinclient")
public interface FeignInterface {
@GetMapping("/zipkin/get")
public String addItem( @RequestParam("desc") String desc);
@GetMapping("/zipkin/geterro")
public String addI( @RequestParam("desc") String desc);
}
--------------------------------------------------------------
@RestController
public class HelloController {
@RequestMapping("/hello")
public String getHello()
{
return "this is hello world";
}
@Autowired
FeignInterface feign;
@RequestMapping("/get")
public String get()
{
return feign.addItem("this is feign get");
}
@RequestMapping("/mm")
public String mm()
{
return feign.addI("this is feign mmmm");
}
}
最新文章
- C和指针 第十五章 习题
- 利用Highcharts插件制作动态图表
- 利用奇异值分解(SVD)简化数据
- spring mvc处理静态资源
- 招聘一个靠谱的 iOS程序员
- find-all-anagrams-in-a-string
- 关于Token
- *MySQL卸载之后无法重装,卡在Apply security settings:Error Nr.1045
- Android Studio 1.2.2设置显示行号
- ORACLE 本地数据库存储过程 调用远程数据库存储过程
- 146. 大小写转换 II
- BZOJ2828 : 火柴游戏
- C++ 中 #ifndef, #define, #endif 宏定义
- 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】
- JS----贪吃蛇游戏
- android 横竖屏 切换
- remove unusable kernel in linux.
- tomcat安装配置常见问题详解
- JAVA之异常处理(一)
- Excel 2010 Alt+; (分号) --- “只选定当前选定区域中的可视单元格”