一、簡介
Spring Boot Admin 客戶端的搭建是很簡單的。通過 maven 引入 spring-boot-admin-starter-client,maven就會將必要的jar包引入到項目中,其中就包括actuator。在通過簡單的配置就可以在Spring Boot Admin 服務端監控微服務應用即Spring Boot應用。
二、實戰
1、項目結構
2、microservice-provider -> pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>microservice-minitor</artifactId> <groupId>com.microservice</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>microservice-provider</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.2.0</version> </dependency> </dependencies> </project>
3、microservice-provider -> application.yml
spring:
application:
name: microservice-provider
boot:
admin:
client:
url: http://localhost:8888
server:
port: 8101
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
至此客戶端配置就完成了。其實Consumer和Provider的配置類似
三、運行測試
1、啟動 microservice-monitor-server
2、啟動microservice-provider,可以多啟動幾個實例。
3、啟動microservice-consumer
打開瀏覽器:http://localhost:8888/wallboard
並查看其中一個實例,看看都有啥:
運行成功,效果完美!