Skip to content

Commit

Permalink
更新 Spring Cloud Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
huzhicheng committed Sep 30, 2019
1 parent f6e74a2 commit 8e437d5
Show file tree
Hide file tree
Showing 80 changed files with 628 additions and 27,188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ public String toString() {
private String env;

private UserInfo user;

}
80 changes: 80 additions & 0 deletions consul/consul-order/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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>consul</artifactId>
<groupId>kite.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>kite.springcloud</groupId>
<artifactId>consul-order</artifactId>

<name>consul-order</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kite.springcloud.consul.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
* @author fengzheng
* @date 2018-11-23
* Application
* 注册到 consul 上的 user 服务
*/
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kite.springcloud.consul.order.controller;

import kite.springcloud.consul.order.entity.CustomerOrder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* ProductController
*
* @author fengzheng
* @date 2019/8/29
*/
@RestController
@RequestMapping(value = "order")
public class OrderController {

@Value("${spring.application.name}")
private String applicationName;


@GetMapping(value = "get")
public CustomerOrder getOrder(){
CustomerOrder customerOrder = new CustomerOrder();
customerOrder.setOrderId("9999");
customerOrder.setProductName("MacBook Pro");
customerOrder.setClient(applicationName);
return customerOrder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kite.springcloud.consul.order.entity;

import lombok.Data;

/**
* CustomerOrder
*
* @author fengzheng
* @date 2019/8/29
*/
@Data
public class CustomerOrder {

private String orderId;

private String productName;

private String client;
}
44 changes: 44 additions & 0 deletions consul/consul-order/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
spring:
profiles:
active: consul-order
cloud:
consul:
discovery:
service-name: consul-order
host: localhost
port: 8500


management:
endpoint:
health:
enabled: true


---
spring:
profiles: consul-order
application:
name: consul-order
server:
port: 5006



---
spring:
profiles: consul-order-other
application:
name: consul-order-other
server:
port: 5007


---
spring:
profiles: consul-order-next
application:
name: consul-order-next
server:
port: 5008

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -24,13 +25,17 @@ public class HelloController {
@Autowired
private DiscoveryClient discoveryClient;

@Value("${spring.application.name}")
private String applicationName;

@GetMapping(value = "test")
public String test(){

List<String> services = discoveryClient.getServices();
for(String s : services){
log.info(s);
}
return "hello spring cloud!";
return "hello spring cloud!" + applicationName;
}

@GetMapping(value = "nice")
Expand Down
80 changes: 80 additions & 0 deletions consul/consul-user/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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>consul</artifactId>
<groupId>kite.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>kite.springcloud</groupId>
<artifactId>consul-user</artifactId>

<name>consul-user</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kite.springcloud.consul.user;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
* @author fengzheng
* @date 2018-11-23
* Application
* 注册到 consul 上的 user 服务
*/
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kite.springcloud.consul.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
* RateLimiterController
*
* @author fengzheng
* @date 2019/9/27
*/
@RestController
@RequestMapping(value = "limiter")
@Slf4j
public class RateLimiterController {


@GetMapping(value = "test")
public String test(){
log.info("");
return "正常返回";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kite.springcloud.consul.user.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* TimeOutController
*
* @author fengzheng
* @date 2019/9/26
*/
@RestController
@RequestMapping(value = "timeout")
public class TimeOutController {

@GetMapping(value = "ok")
public String ok(){
return "我没有超时";
}

@GetMapping(value = "fail")
public String fail() throws Exception{
Thread.sleep(3000);
return "我可能超时了,因为我睡了 3 秒";
}
}
Loading

0 comments on commit 8e437d5

Please sign in to comment.