Access using the unified gateway
Introduction to the
Routing is an integral part of the microservices architecture. For example, / might be mapped to your Web application, / API/Users is mapped to user services, and/API/shop is mapped to shop services. Zuul is a JVM-based router and server-side load balancer provided by Netflix. Here is how to use Zuul. GateWay’s in Alibaba.
Netflix uses Zuul for the following purposes:
-
authentication
-
insights
-
Pressure test
-
Grayscale release test
-
Dynamic routing
-
Service migration
-
lightening
-
security
-
Static response processing
-
Active/Active traffic management
Creating a Routing Gateway
The pom. XML configuration file is as follows
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-zuul</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>hello-spring-cloud-zuul</name>
<description>Creating a Routing Gateway</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0. RELEASE</version>
<configuration>
<mainClass>com.wujie.hello.spring.cloud.zuul.HelloSpringCloudZuulApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Copy the code
application.yml
spring:
application:
name: hello-spring-cloud-zuul
server:
port: 8766
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
zuul:
routes:
ribbon:
path: /ribbon/**
serviceId: HELLO-SPRING-CLOUD-WEB-ADMIN-RIBBON
stripPrefix: true
fegin:
path: /fegin/**
serviceId: HELLO-SPRING-CLOUD-WEB-ADMIN-FEGIN
stripPrefix: true
Copy the code
Annotate @enableZuulProxy on the startup class and start it
@SpringBootApplication
@EnableZuulProxy
public class HelloSpringCloudZuulApplication {
public static void main(String[] args) { SpringApplication.run(HelloSpringCloudZuulApplication.class, args); }}Copy the code
Separate access: Changes have been made to fegin and the Ribbon and admin return simplifications to display ports so that we can clearly see the forwarding success
http://localhost:8766/ribbon/hi?message=helloCloud
http://localhost:8766/fegin/hi?message=helloCloud
Callback when configuring gateway routing fails
When fusing a given route in Zuul, you can provide a fallback response by creating a bean of type FallbackProvider. In this bean, you need to specify the route ID for the fallback and provide the ClientHttpResponse as the fallback return. The following example shows a relatively simple FallbackProvider implementation:
@Component
public class WebAdminRoutesFallbackProvider implements FallbackProvider {
@Override
public String getRoute(a) {
// ServiceId. Return "*" or return null if rollback is required for all calls
// return "HELLO-SPRING-CLOUD-WEB-ADMIN-FEGIN";
return null;
}
@Override
public ClientHttpResponse fallbackResponse(String route, final Throwable cause) {
if (cause instanceof HystrixTimeoutException) {
return response(HttpStatus.GATEWAY_TIMEOUT);
} else {
returnresponse(HttpStatus.INTERNAL_SERVER_ERROR); }}private ClientHttpResponse response(final HttpStatus status) {
return new ClientHttpResponse() {
/** * The gateway failed to make a request to the API service, but the consumer client made a successful request to the gateway@return
* @throws IOException
*/
@Override
public HttpStatus getStatusCode(a) throws IOException {
return status;
}
@Override
public int getRawStatusCode(a) throws IOException {
return status.value();
}
@Override
public String getStatusText(a) throws IOException {
return status.getReasonPhrase();
}
@Override
public void close(a) {}@Override
public InputStream getBody(a) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = new HashMap<>();
map.put("status".200);
map.put("message"."Unable to connect. Please check your network.");
return new ByteArrayInputStream(objectMapper.writeValueAsString(map).getBytes("UTF-8"));
}
@Override
public HttpHeaders getHeaders(a) {
HttpHeaders headers = new HttpHeaders();
// Same as the content encoding in getBody
headers.setContentType(MediaType.APPLICATION_JSON);
returnheaders; }}; }}Copy the code
If you want to provide a default fallback for all routes, you can create a Bean of type FallbackProvider and have the getRoute method return * or NULL.
You can define a gateway route filter
@Component
public class LoginFilter extends ZuulFilter {
private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class);
Pre: before the route * 2. Routing: before the route * 3. Post: after the route * 4. Error: sends error calls *@return* /
@Override
public String filterType(a) {
return "pre";
}
/** * Configure the filtering order *@return* /
@Override
public int filterOrder(a) {
return 0;
}
/** * Whether the configuration requires filtering: true/ yes, false/ no *@return* /
@Override
public boolean shouldFilter(a) {
return true;
}
/** * The business code for the filter *@return
* @throws ZuulException
*/
@Override
public Object run(a) throws ZuulException {
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
String auth = request.getHeader("auth");
logger.info("{} > > > {}", request.getMethod(), request.getRequestURL().toString());
if(! StringUtils.isNotBlank(auth)) { logger.warn("Permission authentication failed");
context.setSendZuulResponse(false);
context.setResponseStatusCode(401);
context.getResponse().setCharacterEncoding("UTF-8");
context.getResponse().setContentType("text/html; cahrset=UTF-8");
try {
context.getResponse().getWriter().write("Permission authentication failed");
} catch (IOException e) {
}
} else {
logger.info("OK");
}
return null; }}Copy the code
Note: when the Chinese prompt is returned, it needs to be added
context.getResponse().setCharacterEncoding("UTF-8"); context.getResponse().setContentType("text/html; cahrset=UTF-8");Copy the code
Otherwise, Chinese garbled characters will appear
With the customization done, we restart the project
First visit without header information: http://localhost:8766/ribbon/hi? Message =helloCloud prompts permission authentication failure
The second add header information visit: http://localhost:8766/ribbon/hi? Message =helloCloud returns the correct result information
Configuration center
Introduction to the
Spring Cloud Config provides server-side and client-side support for externalized configuration in distributed systems. With Config Server, you can manage the external properties of applications in all environments from a central location. The concepts on the client and server are exactly the same as the Spring Environment and PropertySource abstractions, so they are well suited to Spring applications, but can be used with any application running in any language. As applications move through the entire deployment pipeline from developer to tester to production, you can manage the configuration between these environments and ensure that applications have everything they need to migrate. The default implementation of the server storage back uses Git, so it can easily support configuring tagged versions of the environment and managing content through various tools to access it. It is easy to add an alternative implementation and plug it into a Spring configuration.
Create a configuration center server
The pom. XML configuration file is as follows
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-config</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>hello-spring-cloud-config</name>
<description>Create a profile center</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0. RELEASE</version>
<configuration>
<mainClass>com.wujie.hello.spring.cloud.config.HelloSpringCloudConfigApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Copy the code
application.yml
spring:
application:
name: hello-spring-cloud-config
cloud:
config:
server:
git:
uri: https://gitee.com/wujiele/respo.git
search-paths: reps
username:
password:
server:
port: 8888
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Copy the code
The configuration description is as follows:
spring.cloud.config.label
: Configures branches of the repositoryspring.cloud.config.server.git.uri
Git repository: GitHub, GitLab, code cloud…spring.cloud.config.server.git.search-paths
: Configuration repository path (directory where configuration files are stored)spring.cloud.config.server.git.username
: Account used to access the Git repositoryspring.cloud.config.server.git.password
: Password to access the Git repository
Matters needing attention:
- If WE use GitLab as a warehouse,
git.uri
You need to add it at the end.git
, GitHub does not
Enable the configuration center service by annotating @enableconFigServer on the startup class
@SpringBootApplication
@EnableConfigServer
public class HelloSpringCloudConfigApplication {
public static void main(String[] args) { SpringApplication.run(HelloSpringCloudConfigApplication.class, args); }}Copy the code
Start the project visit: http://localhost:8888/config-client/dev/master the following figure:
Attached: HTTP request address and resource file mapping
- http://ip:port/{application}/{profile}[/{label}]
- http://ip:port/{application}-{profile}.yml
- http://ip:port/{label}/{application}-{profile}.yml
- http://ip:port/{application}-{profile}.properties
- http://ip:port/{label}/{application}-{profile}.properties
Create a configuration center client
The pom. XML configuration file is as follows
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-config-client</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>hello-spring-cloud-config-client</name>
<description>Create a profile client</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0. RELEASE</version>
<configuration>
<mainClass>com.wujie.hello.spring.cloud.config.client.HelloSpringCloudConfigClientApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Copy the code
application.yml
spring:
application:
name: hello-spring-cloud-config-client
cloud:
config:
uri: http://localhost:8888
name: config-client
label: master
profile: dev
server:
port: 8889
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Copy the code
The configuration description is as follows:
-
Spring.cloud.config. uri: indicates the url of the configuration service center
-
Spring.cloud.config. name: prefix of the configuration file name
-
Spring. Cloud. Config. Label: configuration branch warehouse
-
spring.cloud.config.profile Copy the code
: Environment identifier of the configuration file
- Dev: indicates the development environment
- Test: indicates the test environment
- Prod: indicates the production environment
Note: The default port for the server is 8888. If the default port is changed, the client project cannot configure spring.cloud.config.uri in application.yml or application.properties. Yml or bootstrap.properties must be configured because the configuration file starting with bootstrap will be loaded and configured first
Create the TestController test class
@RestController
public class TestController {
@Value("${wujie}")
private String name;
@RequestMapping(value = "/hi", method = RequestMethod.GET)
public String hi(a) {
returnname; }}Copy the code
Add the @enableDiscoveryClient annotation to the startup class to start the service
After the startup is complete, you will see that our port number is different from the one in the configuration file, because I reconfigured the port number remotely
Use the new port number to access http://localhost:7010/hi
If the value is the same as the remote configuration, the configuration is successful.
Service link tracing
Introduction to the
Spring Cloud Sleuth implements a distributed tracing solution for Spring Cloud.
Spring Cloud Sleuth implements a distributed tracking solution for Spring Cloud.
The term
Spring Cloud Sleuth borrows Dapper’s terminology.
Spring Cloud Sleuth borrowed Dapper’s terminology.
Span: The basic unit of work. For example, sending an RPC is a new span, as is sending a response to an RPC. Spans are identified by a unique 64-bit ID for the span and another 64-bit ID for the trace the span is a part of. Spans also have other data, such as descriptions, timestamped events, key-value annotations (tags), the ID of the span that caused them, and process IDs (normally IP addresses).
Span: The basic unit of work. For example, sending an RPC is the new span, just like sending a response to an RPC. The span is identified by the span’s unique 64-bit ID and another 64-bit ID of the trace to which the span belongs. The span also has other data, such as descriptions, time-stamped events, key-value annotations (labels), the span ID and process ID (usually IP address) that caused the span
Trace: A set of spans forming a tree-like structure. For example, if you run a distributed big-data store, a trace might be formed by a PUT
request.
**Trace:** A set of spans that form a tree structure. For example, if you are running a distributed big data store, the trace may be formed by PUT requests.
Annotation: Used to record the existence of an event in time. With Brave instrumentation, we no longer need to set special events for Zipkin to understand who the client and server are, where the request started, and where it ended. For learning purposes, however, we mark these events to highlight what kind of an action took place.
- cs: Client Sent. The client has made a request. This annotation indicates the start of the span.
- sr: Server Received: The server side got the request and started processing it. Subtracting the
cs
timestamp from this timestamp reveals the network latency. - ss: Server Sent. Annotated upon completion of request processing (when the response got sent back to the client). Subtracting the
sr
timestamp from this timestamp reveals the time needed by the server side to process the request. - cr: Client Received. Signifies the end of the span. The client has successfully received the response from the server side. Subtracting the
cs
timestamp from this timestamp reveals the whole time needed by the client to receive the response from the server.
**Annotation:** Used to record the presence of events in a timely manner. With the Brave tool, we no longer need to set special events for Zipkin to know who the client and server are, where the request starts, and where it ends. However, for learning purposes, we flag these events to highlight what kind of action occurred.
- Cs: sent by the client. The client made a request. This comment indicates the beginning of the span.
- Sr: Received server: The server side receives the request and begins processing it. Subtracting the CS timestamp from this timestamp reveals the network delay.
- Ss: The server has sent the packet. Annotations are added when the request processing is complete (when the response is sent back to the client). Subtracting the SR timestamp from this timestamp shows how long it took the server side to process the request.
- Cr: Customer received. Indicates the end of the span. The client has successfully received the response from the server. Subtracting the CS timestamp from this timestamp shows the total time required for the client to receive the response from the server.
Zipkin profile
ZipKin is an open source distributed tracking system, open sourced by Twitter, that collects timed data from services to address latency issues in microservices architecture, including data collection, storage, lookup, and presentation. Its theoretical model comes from The Google Dapper paper.
Each service reports timing data to ZipKin, and ZipKin generates a dependency graph through ZipKin UI based on the invocation relationship, showing how many tracking requests pass through each service. The system allows developers to easily collect and analyze data through a Web front end, such as the processing time of each service request. Easy monitoring of bottlenecks in the system.
Graphically annotate Span and Trace using Zipkin annotations in one system:
! [Zipkin annotation process] (wujiele. Gitee. IO/image/Zipki… Annotation process. PNG)
Create the ZipKin server
Zipkin runs in three ways: Java, Docker, and source code compilation. Here I directly use the Java way, interested in you can go to the official website to check other ways:
After SpringBoot 2.0, you do not need to build Zipkin-Server by yourself. Instead, you directly use the compiled JAR package provided by the official, and run the following command to download and start Zipkin-Server at the terminal:
curl -sSL https://zipkin.io/quickstart.sh | bash -s
java -jar zipkin.jar
Copy the code
After running with the Java command, you can visit http://localhost:9411 to view the interface
Add dependencies to the project you want to track, and add configurations to the configuration file
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
Copy the code
zipkin:
base-url: http://localhost:9411
Copy the code
Then restart the project, test the interface you wrote earlier, and you can view it in Zipkin
This indicates that zipkin configuration is successful.
The monitoring system
Introduction to the
As the development cycle progresses, the project grows larger and more services are shelled out, making the microservices a complex system. It becomes a challenge to collect metrics such as health, number of sessions, number of concurrent sessions, service resources, and latency for each microservice system. Spring Boot Admin emerged at the historic moment, it formally developed a powerful monitoring and management system based on these requirements.
Spring Boot Admin provides the following features for registered applications:
- Show health status
- Show details, like
- JVM & memory metrics
- micrometer.io metrics
- Datasource metrics
- Cache metrics
- Show build-info number
- Follow and download logfile
- View jvm system- & environment-properties
- View Spring Boot Configuration Properties
- Support for Spring Cloud’s postable /env- &/refresh-endpoint
- Easy loglevel management
- Interact with JMX-beans
- View thread dump
- View http-traces
- View auditevents
- View http-endpoints
- View scheduled tasks
- View and delete active sessions (using spring-session)
- View Flyway / Liquibase database migrations
- Download heapdump
- Notification on status change (via e-mail, Slack, Hipchat, …)
- Event journal of status changes (non persistent)
Spring Boot Admin provides the following capabilities for registered applications:
- Show health
- Displays detailed information, for example
- JVM and memory metrics
- Micrometer. IO indicators
- Data source index
- Cache indicators
- Display the build information number
- Watch and download log files
- View JVM system and environment properties
- View Spring Boot configuration properties
- Support for Spring Cloud publishable/env-&/ refresh-endpoint
- Easy log level management
- Interact with JMX – beans
- Viewing thread garbage
- Viewing HTTP Traces
- View audit events
- Viewing HTTP endpoints
- Viewing scheduled Tasks
- View and Delete active sessions (using spring-Session)
- Check out the Flyway/Liquibase database migration
- Download heap memory
- Notification of status changes (via email, Slack, Hipchat, etc.)
- Event logs of state changes (non-persistent)
Spring Boot Admin consists of two roles, one is the Spring Boot Admin Server, one is the Spring Boot Admin Client. This chapter will guide you to implement the Spring Boot Admin setup.
Spring Boot Admin server
The pom. XML configuration file is as follows
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-admin</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>hello-spring-cloud-admin</name>
<description>SpringBootAdmin server</description>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.3.0</version>
</dependency>
<! -- Spring Cloud Begin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<! -- Spring Cloud End -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0. RELEASE</version>
<configuration>
<mainClass>com.wujie.hello.spring.cloud.admin.HelloSpringCloudAdminApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Copy the code
application.yml
spring:
application:
name: hello-spring-cloud-admin
zipkin:
base-url: http://localhost:9411
server:
port: 8767
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Copy the code
Annotate the @enableadMinServer on the startup class and start
@SpringBootApplication
@EnableAdminServer
public class HelloSpringCloudAdminApplication {
public static void main(String[] args) { SpringApplication.run(HelloSpringCloudAdminApplication.class, args); }}Copy the code
Visit http://localhost:8767 and you can see the picture
SpringBootAdmin client
The pom. XML configuration file is as follows
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-dependencies</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.wujie</groupId>
<artifactId>hello-spring-cloud-admin-client</artifactId>
<version>0.0.1 - the SNAPSHOT</version>
<name>hello-spring-cloud-admin-client</name>
<description>Spring Boot Admin client</description>
<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.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.2.5. RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0. RELEASE</version>
<configuration>
<mainClass>com.wujie.hello.spring.cloud.admin.client.HelloSpringCloudAdminClientApplication
</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Copy the code
application.yml
spring:
application:
name: hello-spring-cloud-admin-client
boot:
admin:
client:
url: http://localhost:8767
zipkin:
base-url: http://localhost:9411
server:
port: 8768
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
management:
endpoints:
web:
exposure:
include: The '*'
endpoint:
health:
show-details: ALWAYS
Copy the code
Note:
management: endpoints: web: exposure: include: ‘*’ endpoint: health: show-details: ALWAYS
This is configured on the client to display information. A lot of the Internet is put on the server, the result of access to no information like this picture
This is what it looks like if it’s configured correctly
At this point, the configuration is successful.
tips
Whether for micro service or some other technology, we can only hold a modest attitude to learn, explore knowledge to get what you want, also don’t be afraid of English literature, whether in baidu or Google up search is always secondary third even N hand data, the official is the latest first-hand information, There are even various versions, but most of them are In English. At this time, we cannot be afraid to learn. There are so many online translation software that we first try to read and then use translation software to translate. The advantage of doing this is that we can further improve our English level, and we can remember the document at least three times (try to translate by ourselves first, use translation software to translate, and take notes), and also deepen our understanding of this technology.
The ancients said that reviewing the old and knowing the new can be a teacher