Preface:
In the production environment, it is impossible for us to leak out the true information of each service, because it is too unsafe.
We will choose to use the routing agent to forward the real service information.
Create a new Zool:
1. Adding dependencies
<?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"> <modelVersion>4.0.0</modelVersion> <groupId>com.xm.cloud</groupId> <artifactId>cl_zool</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>cl_zool</name> <description>This is a Web about springcloud</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.SR2</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2. Modify configuration
server.port=9090 spring.application.name=cl-zool-gateway eureka.client.service-url.defaultZone=http://127.0.0.1:7001/eureka/ #Uniform prefix of service name zuul.prefix=/xm #True name hiding for all services zuul.ignored-services="*" zuul.routes.myHello.service-id=CL-HELLO-PRODUCER zuul.routes.myHello.path=/myHello/**
3. Open Notes
package com.xm.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @EnableDiscoveryClient @EnableZuulProxy @SpringBootApplication public class ClZoolApplication { public static void main(String[] args) { SpringApplication.run(ClZoolApplication.class, args); } }
Test:
Open Eureka 7001, service producer 8001, route zool 9090