spring-boot-starter-parent
2.1.4.RELEASE
com.cloud
zipkin-server
0.0.1-SNAPSHOT
zipkin-server
Demo project for Spring Boot
<java.version>1.8</java.version>
org.springframework.boot
spring-boot-starter
io.zipkin.java
zipkin-server
2.11.8
io.zipkin.java
zipkin-autoconfigure-ui
2.11.8
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
2.0.0.RELEASE
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
然后是application.yml:
server:
port: 9411
spring:
application:
name: zipkin-server
management:
metrics:
web:
server:
auto-time-requests: false
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
preferIpAddress: true
instance-id: s p r i n g . c l o u d . c l i e n t . i p − a d d r e s s : {spring.cloud.client.ip-address}: spring.cloud.client.ip−address:{server.port}
到这里,其实ZipKin Server这一段我们已经完成了。
我们可以将项目跑起来(记得前提eureka注册中心是正常运行的,我们有做注册),访问 http://localhost:9411/ :
ZipKin服务端是正常部署运行了,那么我们需要在各个微服务上也整合这个组件,这样才能将微服务与ZipKin Server互通。
我们在网关服务,gateway的pom.xml导入依赖:
org.springframework.cloud
spring-cloud-starter-sleuth
2.0.0.RELEASE
org.springframework.cloud
spring-cloud-starter-zipkin
2.0.0.RELEASE
在application.yml上添加相关的配置项后:
server:
port: 8081
spring:
application:
name: gateway-service
zipkin:
base-url: http://localhost:9411
sender:
type: web
sleuth:
sampler:
#采样100%
probability: 1.0
cloud:
gateway:
discovery:
locator:
enabled: false
#开启小写验证,默认feign根据服务名查找都是用的全大写
lowerCaseServiceId: true
routes:
- id: client-test
uri: lb://CLIENT-TEST
predicates:
- Path=/testclient/**
filters:
-
StripPrefix=1
-
id: service-feign
uri: lb://FEIGN
predicates:
- Path=/service-feign/**
filters:
- StripPrefix=1
eureka:
instance:
preferIpAddress: true
instance-id: s p r i n g . c l o u d . c l i e n t . i p − a d d r e s s : {spring.cloud.client.ip-address}: spring.cloud.client.ip−address:{server.port}