16 changed files with 435 additions and 77 deletions
@ -0,0 +1,81 @@ |
|||||||
|
<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> |
||||||
|
<parent> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||||
|
<version>2.0.3.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>config-client</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>config-client</name> |
||||||
|
<packaging>jar</packaging> |
||||||
|
|
||||||
|
<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.RELEASE</spring-cloud.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<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> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!-- Spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来。它可以用于广播配置文件的更改或者服务之间的通讯,也可以用于监控 --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-bus-amqp</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId> |
||||||
|
</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> |
||||||
|
<finalName>configClient</finalName> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<executable>true</executable> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,31 @@ |
|||||||
|
package vip.xumy.learn.config.client; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaClient |
||||||
|
@EnableDiscoveryClient |
||||||
|
@RestController |
||||||
|
@RefreshScope |
||||||
|
public class ConfigClientApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run(ConfigClientApplication.class, args); |
||||||
|
} |
||||||
|
|
||||||
|
@Value("${foo}") |
||||||
|
String foo; |
||||||
|
@RequestMapping(value = "/hi") |
||||||
|
public String hi(){ |
||||||
|
return foo; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,20 @@ |
|||||||
|
spring.application.name=config-client |
||||||
|
spring.cloud.config.label=master |
||||||
|
spring.cloud.config.profile=dev |
||||||
|
spring.cloud.config.uri= http://localhost:8888/ |
||||||
|
server.port=8881 |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://cloud.xumy.vip/eureka/ |
||||||
|
spring.cloud.config.discovery.enabled=true |
||||||
|
spring.cloud.config.discovery.serviceId=config-server |
||||||
|
|
||||||
|
|
||||||
|
spring.rabbitmq.host=mq.xumy.vip |
||||||
|
spring.rabbitmq.port=5672 |
||||||
|
spring.rabbitmq.username=admin |
||||||
|
spring.rabbitmq.password=123456 |
||||||
|
|
||||||
|
spring.cloud.bus.enabled=true |
||||||
|
spring.cloud.bus.trace.enabled=true |
||||||
|
management.endpoints.web.exposure.include=bus-refresh |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,72 @@ |
|||||||
|
<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> |
||||||
|
<parent> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||||
|
<version>2.0.3.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>config-server</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>config-server</name> |
||||||
|
<packaging>jar</packaging> |
||||||
|
|
||||||
|
<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.RELEASE</spring-cloud.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-config-server</artifactId> |
||||||
|
</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> |
||||||
|
<finalName>configServer</finalName> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<executable>true</executable> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,16 @@ |
|||||||
|
package vip.xumy.learn.config.server; |
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import org.springframework.cloud.config.server.EnableConfigServer; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableConfigServer |
||||||
|
public class ConfigServerApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run(ConfigServerApplication.class, args); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,11 @@ |
|||||||
|
spring.application.name=config-server |
||||||
|
server.port=8888 |
||||||
|
|
||||||
|
spring.cloud.config.server.git.uri=https://www.xumy.vip/mengyxu/cloudConfig |
||||||
|
spring.cloud.config.server.git.searchPaths=respo |
||||||
|
spring.cloud.config.label=master |
||||||
|
spring.cloud.config.server.git.username= |
||||||
|
spring.cloud.config.server.git.password= |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://eureka1.xumy.vip/eureka/ |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,72 @@ |
|||||||
|
<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> |
||||||
|
<parent> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||||
|
<version>2.0.3.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>eureka-client-zuul</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>eureka-client-zuul</name> |
||||||
|
<packaging>jar</packaging> |
||||||
|
|
||||||
|
<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.RELEASE</spring-cloud.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-zuul</artifactId> |
||||||
|
</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> |
||||||
|
<finalName>zuul</finalName> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<executable>true</executable> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,65 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import com.netflix.zuul.ZuulFilter; |
||||||
|
import com.netflix.zuul.context.RequestContext; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class MyFilter extends ZuulFilter { |
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(MyFilter.class); |
||||||
|
|
||||||
|
/** |
||||||
|
* filterType:返回一个字符串代表过滤器的类型,在zuul中定义了四种不同生命周期的过滤器类型,具体如下: pre:路由之前 |
||||||
|
* routing:路由之时 post: 路由之后 error:发送错误调用 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String filterType() { |
||||||
|
return "pre"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* filterOrder:过滤的顺序 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public int filterOrder() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* shouldFilter:这里可以写逻辑判断,是否要过滤,true,永远过滤。 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean shouldFilter() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* run:过滤器的具体逻辑。可用很复杂,包括查sql,nosql去判断该请求到底有没有权限访问。 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Object run() { |
||||||
|
RequestContext ctx = RequestContext.getCurrentContext(); |
||||||
|
HttpServletRequest request = ctx.getRequest(); |
||||||
|
log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString())); |
||||||
|
Object accessToken = request.getParameter("token"); |
||||||
|
if (accessToken == null) { |
||||||
|
log.warn("token is empty"); |
||||||
|
ctx.setSendZuulResponse(false); |
||||||
|
ctx.setResponseStatusCode(401); |
||||||
|
try { |
||||||
|
ctx.getResponse().getWriter().write("token is empty"); |
||||||
|
} catch (Exception e) { |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
log.info("ok"); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; |
||||||
|
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaClient |
||||||
|
@EnableDiscoveryClient |
||||||
|
@EnableZuulProxy |
||||||
|
public class ServiceZuulApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run( ServiceZuulApplication.class, args ); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,10 @@ |
|||||||
|
server.port=8080 |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ |
||||||
|
|
||||||
|
spring.application.name=eureka-zuul |
||||||
|
|
||||||
|
zuul.routes.ribbon.path=/ribbon/** |
||||||
|
zuul.routes.ribbon.serviceId=eureka-ribbon |
||||||
|
zuul.routes.feign.path=/feign/** |
||||||
|
zuul.routes.feign.serviceId=eureka-feign |
@ -1,6 +1,6 @@ |
|||||||
server.port=8762 |
server.port=8763 |
||||||
|
|
||||||
eureka.client.serviceUrl.defaultZone=http://eureka.xumy.vip/eureka/ |
eureka.client.serviceUrl.defaultZone=http://eureka1.xumy.vip/eureka/ |
||||||
|
|
||||||
spring.application.name=eureka-hi |
spring.application.name=eureka-hi |
||||||
|
|
||||||
|
@ -1,63 +0,0 @@ |
|||||||
<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> |
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.0.3.RELEASE</version> |
|
||||||
</parent> |
|
||||||
<groupId>vip.xumy.learn</groupId> |
|
||||||
<artifactId>spring-cloud-demo</artifactId> |
|
||||||
<version>1.0.0.RELEASE</version> |
|
||||||
<name>spring-cloud-demo</name> |
|
||||||
<packaging>pom</packaging> |
|
||||||
|
|
||||||
<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.RELEASE</spring-cloud.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<modules> |
|
||||||
<module>../eureka-server</module> |
|
||||||
<module>../service-hi</module> |
|
||||||
<module>../service-ribbon</module> |
|
||||||
</modules> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
|
|
||||||
<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> |
|
||||||
<configuration> |
|
||||||
<executable>true</executable> |
|
||||||
</configuration> |
|
||||||
</plugin> |
|
||||||
</plugins> |
|
||||||
</build> |
|
||||||
|
|
||||||
</project> |
|
Loading…
Reference in new issue