├── .gitignore
├── README.md
├── pom.xml
├── spring-cloud-config-client
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── config
│ │ └── client
│ │ ├── ConfigClientApplication.java
│ │ ├── controller
│ │ ├── ClientController.java
│ │ └── MessageController.java
│ │ ├── properties
│ │ └── JpushCenterProperties.java
│ │ ├── schedule
│ │ └── PropertiesSchedule.java
│ │ └── utils
│ │ └── HttpUtils.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-config-server
├── pom.xml
└── src
│ └── main
│ ├── docker
│ └── Dockerfile
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── config
│ │ └── server
│ │ └── ConfigServerApplication.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-eureka-client
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── eureka
│ │ └── client
│ │ ├── EurekaClientApplication.java
│ │ ├── controller
│ │ ├── CompanyController.java
│ │ ├── EmployeeController.java
│ │ ├── HelloController.java
│ │ └── ProductController.java
│ │ ├── model
│ │ ├── Company.java
│ │ ├── Employee.java
│ │ ├── OneCompany.java
│ │ └── Product.java
│ │ └── rpc
│ │ ├── failure
│ │ ├── ComandCompanyFailure.java
│ │ └── ComandCompanyObservableFailure.java
│ │ ├── feign
│ │ ├── CompanyFeignClient.java
│ │ ├── EmployeeFeignClient.java
│ │ ├── HelloFeignClient.java
│ │ └── ProductFeignClient.java
│ │ ├── hytrix
│ │ ├── CompanyHystrixWrappedClient.java
│ │ ├── EmployeeHystrixClient.java
│ │ ├── HelloHystrixWrappedClient.java
│ │ └── ProductHystrixWrappedClient.java
│ │ └── ribbon
│ │ └── HelloRibbonClient.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-eureka-dashboard
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com.zzqfsy.cloud.eureka.dashboard
│ │ ├── EurekaDashboardApplication.java
│ │ ├── controller
│ │ └── EmployeeController.java
│ │ └── model
│ │ └── Employee.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-eureka-server
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── eureka
│ │ └── server
│ │ ├── EurekaServerApplication.java
│ │ ├── controller
│ │ └── ProductController.java
│ │ └── model
│ │ └── Product.java
│ └── resources
│ ├── application-backup.yml
│ ├── application-dev.yml
│ ├── application-master.yml
│ ├── application-secondary.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-eureka-service
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── eureka
│ │ └── service
│ │ ├── EurekaServiceApplication.java
│ │ ├── api
│ │ └── resp
│ │ │ └── BaseResp.java
│ │ ├── controller
│ │ ├── CompanyController.java
│ │ └── ServiceController.java
│ │ ├── model
│ │ ├── Company.java
│ │ └── OneCompany.java
│ │ └── rpc
│ │ ├── feign
│ │ ├── EmployeeFeignClient.java
│ │ └── ProductFeignClient.java
│ │ ├── hytrix
│ │ ├── EmployeeHystrixClient.java
│ │ └── ProductHystrixClient.java
│ │ └── model
│ │ ├── Employee.java
│ │ └── Product.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-cloud-zuul-server
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── cloud
│ │ └── zuul
│ │ └── ZuulApplication.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ └── bootstrap.yml
├── spring-security-service
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzqfsy
│ │ └── security
│ │ ├── SecurityApplication.java
│ │ ├── config
│ │ ├── OAuth2Config.java
│ │ └── WebSecurityConfig.java
│ │ └── controller
│ │ └── HelloController.java
│ └── resources
│ ├── application-dev.yml
│ ├── application.yml
│ ├── bootstrap.yml
│ └── keystore.jks
├── summery.graphml
└── summery.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Example user template template
3 | ### Example user template
4 |
5 | # IntelliJ project files
6 | .idea
7 | *.iml
8 | out
9 | gen### Maven template
10 | target/
11 | pom.xml.tag
12 | pom.xml.releaseBackup
13 | pom.xml.versionsBackup
14 | pom.xml.next
15 | release.properties
16 | dependency-reduced-pom.xml
17 | buildNumber.properties
18 | .mvn/timing.properties
19 | ### Java template
20 | *.class
21 |
22 | # Mobile Tools for Java (J2ME)
23 | .mtj.tmp/
24 |
25 | # Package Files #
26 | *.jar
27 | *.war
28 | *.ear
29 |
30 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
31 | hs_err_pid*
32 |
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # spring-cloud-demo
2 | 项目demo包含分布式配置[Config](https://github.com/spring-cloud-samples/configserver)、服务发现[Eureka](https://github.com/spring-cloud-samples/eureka)、REST声明式客户端[Feign](https://github.com/spring-cloud-samples/feign-eureka)、断路器[Hystrix](http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)、客户端负载均衡[Ribbon](http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)、服务网关[Zuul](https://github.com/spring-cloud-samples/zuul-server)、鉴权服务[oAuth2](https://github.com/spring-cloud-samples/authserver)。
3 |
4 | # 目录
5 | * [project_summery](#项目结构)
6 | * [spirng-cloud-config-server](#spirng-cloud-config-server)
7 | * [spirng-cloud-config-client](#spirng-cloud-config-client)
8 | * [spirng-cloud-eureka-server](#spirng-cloud-eureka-server)
9 | * [spring-cloud-eureka-service](#spring-cloud-eureka-service)
10 | * [spring-cloud-eureka-client](#spring-cloud-eureka-client)
11 | * [spring-cloud-eureka-dashboard](#spring-cloud-eureka-dashboard)
12 | * [spring-cloud-zuul-server](#spring-cloud-zuul-server)
13 | * [spring-cloud-security-service](#spring-cloud-security-service)
14 |
15 | ## 项目结构:
16 | 
17 |
18 | ## spirng-cloud-config-server
19 |
20 | ## spirng-cloud-config-client
21 |
22 | ## spirng-cloud-eureka-server
23 |
24 | ## spring-cloud-eureka-service
25 |
26 | ## spring-cloud-eureka-client
27 |
28 | ## spring-cloud-eureka-dashboard
29 |
30 | ## spring-cloud-zuul-server
31 |
32 | ## spring-cloud-security-service
33 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.zzqfsy.cloud
8 | spring-cloud-demo
9 | pom
10 | 1.0-SNAPSHOT
11 |
12 |
13 | 1.8
14 |
15 |
16 |
17 | spring-cloud-config-client
18 | spring-cloud-config-server
19 | spring-cloud-eureka-server
20 | spring-cloud-eureka-client
21 | spring-cloud-eureka-service
22 | spring-cloud-eureka-dashboard
23 | spring-cloud-zuul-server
24 | spring-security-service
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-parent
30 | 1.4.1.RELEASE
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.cloud
37 | spring-cloud-config
38 | 1.2.0.RELEASE
39 | pom
40 | import
41 |
42 |
43 | org.springframework.cloud
44 | spring-cloud-netflix
45 | 1.2.1.BUILD-SNAPSHOT
46 | pom
47 | import
48 |
49 |
50 |
51 |
52 |
53 |
54 | spring-snapshots
55 | Spring Snapshots
56 | https://repo.spring.io/libs-snapshot
57 |
58 | true
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-config-client
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.config.client.ConfigClientApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-config-client
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-actuator
32 |
33 |
34 |
35 |
36 | org.apache.httpcomponents
37 | httpclient
38 | 4.3.5
39 |
40 |
41 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/ConfigClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * Created by john on 16-10-17.
8 | */
9 | @SpringBootApplication
10 | //@EnableScheduling
11 | public class ConfigClientApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(ConfigClientApplication.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/controller/ClientController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client.controller;
2 |
3 | import com.zzqfsy.cloud.config.client.utils.HttpUtils;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * Created by john on 16-10-28.
11 | */
12 | @RestController
13 | public class ClientController {
14 | private static final String CREATE_COMPANY_URL = "http://localhost:8066/api/companys/";
15 | HttpUtils.ParamMap paramMap = new HttpUtils.ParamMap().putParam("companyId", "132");
16 |
17 | @RequestMapping("/createCompany")
18 | public String IAmClient() {
19 | try {
20 | return HttpUtils.post(CREATE_COMPANY_URL, paramMap);
21 | } catch (IOException e) {
22 | e.printStackTrace();
23 | }
24 |
25 | return "error";
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/controller/MessageController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client.controller;
2 |
3 | import com.zzqfsy.cloud.config.client.properties.JpushCenterProperties;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.cloud.context.config.annotation.RefreshScope;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | /**
11 | * Created by john on 16-10-28.
12 | */
13 | @RestController
14 | @RefreshScope
15 | public class MessageController {
16 |
17 | @Value("${apply.message:local message}")
18 | public String message;
19 |
20 | @Autowired
21 | private JpushCenterProperties jpushCenterProperties;
22 |
23 |
24 | @RequestMapping("/")
25 | public String home() {
26 | return message;
27 | }
28 |
29 | @RequestMapping("/title")
30 | public String title() {
31 | return jpushCenterProperties.getTitle();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/properties/JpushCenterProperties.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client.properties;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * Created by john on 16-10-17.
8 | */
9 | @Component
10 | @ConfigurationProperties(prefix = "servers.jpushCenter")
11 | public class JpushCenterProperties {
12 | private String host;
13 | private String title;
14 | private String destination;
15 |
16 | public String getHost() {
17 | return host;
18 | }
19 |
20 | public void setHost(String host) {
21 | this.host = host;
22 | }
23 |
24 | public String getTitle() {
25 | return title;
26 | }
27 |
28 | public void setTitle(String title) {
29 | this.title = title;
30 | }
31 |
32 | public String getDestination() {
33 | return destination;
34 | }
35 |
36 | public void setDestination(String destination) {
37 | this.destination = destination;
38 | }
39 | }
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/schedule/PropertiesSchedule.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client.schedule;
2 |
3 | import com.zzqfsy.cloud.config.client.properties.JpushCenterProperties;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.builder.SpringApplicationBuilder;
6 | import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
7 | import org.springframework.cloud.context.scope.refresh.RefreshScope;
8 | import org.springframework.context.ApplicationContext;
9 | import org.springframework.context.ConfigurableApplicationContext;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.core.env.CompositePropertySource;
12 | import org.springframework.core.env.EnumerablePropertySource;
13 | import org.springframework.core.env.MutablePropertySources;
14 | import org.springframework.core.env.PropertySource;
15 | import org.springframework.core.env.StandardEnvironment;
16 | import org.springframework.scheduling.annotation.Scheduled;
17 | import org.springframework.web.context.support.StandardServletEnvironment;
18 |
19 | import java.util.Arrays;
20 | import java.util.HashMap;
21 | import java.util.HashSet;
22 | import java.util.Map;
23 | import java.util.Set;
24 |
25 | /**
26 | * Created by john on 16-10-17.
27 | */
28 | //@Component
29 | public class PropertiesSchedule {
30 | private Set standardSources = new HashSet(Arrays.asList(
31 | StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
32 | StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
33 | StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME,
34 | StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME,
35 | StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
36 |
37 | @Autowired
38 | private RefreshScope refreshScope;
39 | @Autowired
40 | private ConfigurableApplicationContext context;
41 | @Autowired
42 | private JpushCenterProperties jpushCenterProperties;
43 |
44 | @Scheduled(cron="0/20 * * * * ? ") //每20秒执行一次
45 | public void refreshConfigProperties(){
46 | refresh();
47 | System.out.println("refresh title: " + jpushCenterProperties.getTitle());
48 | }
49 |
50 | /**
51 | * 手动刷新git更新方案,每20S执行一次,可以修改成手动执行,同/refresh
52 | * @link RefreshEndpoint
53 | * */
54 | public void refresh() {
55 | Map before = extract(context.getEnvironment().getPropertySources());
56 | addConfigFilesToEnvironment();
57 | Set keys = changes(before, extract(context.getEnvironment().getPropertySources())).keySet();
58 | refreshScope.refreshAll();
59 |
60 | context.publishEvent(new EnvironmentChangeEvent(keys));
61 | }
62 |
63 | @Configuration
64 | protected static class Empty {
65 |
66 | }
67 |
68 | private void addConfigFilesToEnvironment() {
69 | ConfigurableApplicationContext capture = null;
70 | try {
71 | capture = new SpringApplicationBuilder(Empty.class)
72 | .web(false).environment(context.getEnvironment()).run();
73 | MutablePropertySources target = context.getEnvironment().getPropertySources();
74 | for (PropertySource> source : capture.getEnvironment().getPropertySources()) {
75 | String name = source.getName();
76 | if (!standardSources.contains(name)) {
77 | if (target.contains(name)) {
78 | target.replace(name, source);
79 | }
80 | else {
81 | if (target.contains("defaultProperties")) {
82 | target.addBefore("defaultProperties", source);
83 | }
84 | else {
85 | target.addLast(source);
86 | }
87 | }
88 | }
89 | }
90 | }
91 | finally {
92 | while (capture != null) {
93 | capture.close();
94 | ApplicationContext parent = capture.getParent();
95 | if (parent instanceof ConfigurableApplicationContext) {
96 | capture = (ConfigurableApplicationContext) parent;
97 | } else {
98 | capture = null;
99 | }
100 | }
101 | }
102 | }
103 |
104 | private Map changes(Map before,
105 | Map after) {
106 | Map result = new HashMap();
107 | for (String key : before.keySet()) {
108 | if (!after.containsKey(key)) {
109 | result.put(key, null);
110 | }
111 | else if (!equal(before.get(key), after.get(key))) {
112 | result.put(key, after.get(key));
113 | }
114 | }
115 | for (String key : after.keySet()) {
116 | if (!before.containsKey(key)) {
117 | result.put(key, after.get(key));
118 | }
119 | }
120 | return result;
121 | }
122 |
123 | private boolean equal(Object one, Object two) {
124 | if (one == null && two == null) {
125 | return true;
126 | }
127 | if (one == null || two == null) {
128 | return false;
129 | }
130 | return one.equals(two);
131 | }
132 |
133 | private Map extract(MutablePropertySources propertySources) {
134 | Map result = new HashMap();
135 | for (PropertySource> parent : propertySources) {
136 | if (!standardSources.contains(parent.getName())) {
137 | extract(parent, result);
138 | }
139 | }
140 | return result;
141 | }
142 |
143 | private void extract(PropertySource> parent, Map result) {
144 | if (parent instanceof CompositePropertySource) {
145 | try {
146 | for (PropertySource> source : ((CompositePropertySource) parent)
147 | .getPropertySources()) {
148 | extract(source, result);
149 | }
150 | }
151 | catch (Exception e) {
152 | return;
153 | }
154 | }
155 | else if (parent instanceof EnumerablePropertySource) {
156 | for (String key : ((EnumerablePropertySource>) parent).getPropertyNames()) {
157 | result.put(key, parent.getProperty(key));
158 | }
159 | }
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/java/com/zzqfsy/cloud/config/client/utils/HttpUtils.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.client.utils;
2 |
3 | import org.apache.http.Header;
4 | import org.apache.http.HttpEntity;
5 | import org.apache.http.HttpHeaders;
6 | import org.apache.http.HttpHost;
7 | import org.apache.http.NameValuePair;
8 | import org.apache.http.client.ClientProtocolException;
9 | import org.apache.http.client.config.RequestConfig;
10 | import org.apache.http.client.entity.UrlEncodedFormEntity;
11 | import org.apache.http.client.methods.CloseableHttpResponse;
12 | import org.apache.http.client.methods.HttpGet;
13 | import org.apache.http.client.methods.HttpPost;
14 | import org.apache.http.client.methods.HttpRequestBase;
15 | import org.apache.http.conn.routing.HttpRoute;
16 | import org.apache.http.entity.ContentType;
17 | import org.apache.http.entity.StringEntity;
18 | import org.apache.http.impl.client.CloseableHttpClient;
19 | import org.apache.http.impl.client.HttpClients;
20 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
21 | import org.apache.http.message.BasicHeader;
22 | import org.apache.http.message.BasicNameValuePair;
23 | import org.apache.http.util.EntityUtils;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | import java.io.Closeable;
28 | import java.io.IOException;
29 | import java.util.ArrayList;
30 | import java.util.Arrays;
31 | import java.util.Collection;
32 | import java.util.Date;
33 | import java.util.HashMap;
34 | import java.util.List;
35 | import java.util.Map;
36 | import java.util.Set;
37 |
38 | /**
39 | * HttpUtils 处理http请求
40 | *
41 | * https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
42 | *
43 | * @author stone
44 | *
45 | */
46 | public class HttpUtils {
47 |
48 | private static final Logger LOG = LoggerFactory.getLogger(HttpUtils.class);
49 |
50 | private static CloseableHttpClient httpClient;
51 |
52 | private static final int SOCKET_TIMEOUT = 1000 * 15;
53 | private static final int CONNECT_TIMEOUT = 1000 * 15;
54 |
55 | private static final List DEFAULT_HEADER= Arrays.asList(new BasicHeader(HttpHeaders.CONTENT_ENCODING, "utf-8"));
56 |
57 | static {
58 |
59 | PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
60 | // Increase max total connection to 200
61 | cm.setMaxTotal(200);
62 | // Increase default max connection per route to 20
63 | cm.setDefaultMaxPerRoute(20);
64 | // Increase max connections for localhost:80 to 50
65 | HttpHost localhost = new HttpHost("locahost", 8080);
66 | cm.setMaxPerRoute(new HttpRoute(localhost), 50);
67 |
68 | RequestConfig config = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).setConnectTimeout(CONNECT_TIMEOUT).build();
69 |
70 | httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(config).build();
71 | // .setKeepAliveStrategy(keepAliveStrategy)
72 |
73 | }
74 |
75 | public static String post(String url, List headers, String post) throws IOException, ClientProtocolException {
76 |
77 | return request(new HttpPost(url), headers, null, post);
78 | }
79 |
80 | public static String post(String url, List headers, Map params) throws IOException{
81 | List list=new ArrayList<>();
82 | for(String key:params.keySet())
83 | list.add(new BasicNameValuePair(key,params.get(key)));
84 | return post(url,headers,list);
85 | }
86 |
87 | public static String post(String url, Map params) throws IOException{
88 | List list=new ArrayList<>();
89 | for(String key:params.keySet())
90 | list.add(new BasicNameValuePair(key,params.get(key)));
91 | return post(url,null,list);
92 | }
93 |
94 | public static String post(String url, List headers, List nvps)throws IOException, ClientProtocolException{
95 | return request(new HttpPost(url),headers,nvps,null);
96 | }
97 |
98 | public static String post(String url, String post) throws IOException, ClientProtocolException {
99 |
100 | return request(new HttpPost(url), null, null, post);
101 | }
102 |
103 | public static String get(String url, Map params) throws IOException, ClientProtocolException {
104 | StringBuilder sb=new StringBuilder(url);
105 | if(params!=null){
106 | boolean flag=url.indexOf("?")==-1;
107 | for(String key:params.keySet()){
108 | (flag?sb.append("?"):sb.append("&"))
109 | .append(key).append("=")
110 | .append(params.get(key));
111 | flag=false;
112 | }
113 | }
114 |
115 | return request(new HttpGet(sb.toString()), null, null, null);
116 | }
117 |
118 | public static String get(String url, List headers, Map params) throws IOException, ClientProtocolException {
119 | StringBuilder sb=new StringBuilder(url);
120 | boolean flag=url.indexOf("?")==-1;
121 | for(String key:params.keySet()){
122 | (flag?sb.append("?"):sb.append("&"))
123 | .append(key).append("=")
124 | .append(params.get(key));
125 | flag=false;
126 | }
127 |
128 | return request(new HttpGet(sb.toString()), headers, null, null);
129 | }
130 |
131 | public static String postJson(String uri,String json) throws IOException{
132 | List headers=Arrays.asList(new BasicHeader(HttpHeaders.CONTENT_ENCODING, "utf-8"), new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()));
133 | return request(new HttpPost(uri),headers,null,json);
134 | }
135 |
136 |
137 | private static String request(HttpRequestBase httpRequest, List headers, List nvps, String postData) throws IOException,
138 | ClientProtocolException {
139 | Date start=new Date();
140 | String result = "";
141 | CloseableHttpResponse response = null;
142 |
143 | try {
144 |
145 | if (headers != null && !headers.isEmpty()) {
146 | headers.forEach(header->{httpRequest.addHeader(header);});
147 | }
148 | else{
149 | DEFAULT_HEADER.forEach(header ->httpRequest.addHeader(header));
150 | }
151 |
152 | if (nvps != null && !nvps.isEmpty() && httpRequest instanceof HttpPost) {
153 | ((HttpPost) httpRequest).setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
154 | }
155 |
156 | if (postData != null && httpRequest instanceof HttpPost) {
157 | ((HttpPost) httpRequest).setEntity(new StringEntity(postData,"UTF-8"));
158 | }
159 |
160 | response = httpClient.execute(httpRequest);
161 | HttpEntity entity = response.getEntity();
162 |
163 | result = EntityUtils.toString(entity);
164 |
165 | // do something useful with the response body
166 | // and ensure it is fully consumed
167 | EntityUtils.consume(entity);
168 |
169 | } catch (ClientProtocolException e) {
170 | LOG.error(e.getMessage(), e);
171 | throw e;
172 | } catch (IOException e) {
173 | LOG.error(e.getMessage(), e);
174 | throw e;
175 | } finally {
176 | closeQuietly(response);
177 | }
178 | LOG.warn("http request spend time:"+(new Date().getTime()-start.getTime()));
179 | return result;
180 | }
181 |
182 | private static void closeQuietly(Closeable c) {
183 | try {
184 | if (c != null) {
185 | c.close();
186 | }
187 | } catch (IOException ioe) {
188 | // ignore
189 | }
190 | }
191 |
192 | public static void main(String[] args) throws Exception {
193 |
194 | List headers = new ArrayList();
195 | headers.add(new BasicHeader("Content-Type", "application/json"));
196 |
197 | System.out.println(post("http://127.0.0.1:8080/parameter/get", headers, "{\"param\":{\"id\":\"x\"}}"));
198 | }
199 |
200 | public static class ParamMap implements Map{
201 | private HashMap params=new HashMap<>();
202 | @Override
203 | public int size() {
204 | return params.size();
205 | }
206 |
207 | @Override
208 | public boolean isEmpty() {
209 | return params.isEmpty();
210 | }
211 |
212 | @Override
213 | public boolean containsKey(Object key) {
214 | return params.containsKey(key);
215 | }
216 |
217 | @Override
218 | public boolean containsValue(Object value) {
219 | return params.containsKey(value);
220 | }
221 |
222 | @Override
223 | public String get(Object key) {
224 | return params.get(key);
225 | }
226 |
227 | @Override
228 | public String put(String key, String value) {
229 | return params.put(key,value);
230 | }
231 | public ParamMap putParam(String key,String value){
232 | put(key,value);
233 | return this;
234 | }
235 |
236 | @Override
237 | public String remove(Object key) {
238 | return params.remove(key);
239 | }
240 |
241 | @Override
242 | public void putAll(Map extends String, ? extends String> m) {
243 | params.putAll(m);
244 | }
245 |
246 | @Override
247 | public void clear() {
248 | params.clear();
249 | }
250 |
251 | @Override
252 | public Set keySet() {
253 | return params.keySet();
254 | }
255 |
256 | @Override
257 | public Collection values() {
258 | return params.values();
259 | }
260 |
261 | @Override
262 | public Set> entrySet() {
263 | return params.entrySet();
264 | }
265 | }
266 | }
267 |
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8050
3 |
4 | #servers:
5 | # jpushCenter:
6 | # host: http://127.0.0.1:8073/jpush/send/
7 | # title: 云端钱包测试版
8 | # destination: ydWalletTest
9 | #
10 | #apply:
11 | # message: local message
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
4 | #logging:
5 | # level: trace
--------------------------------------------------------------------------------
/spring-cloud-config-client/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: configclient
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 |
10 | endpoints:
11 | restart:
12 | enabled: true
13 |
14 | logging:
15 | levels:
16 | org.springframework.boot.env.PropertySourcesLoader: TRACE
17 | org.springframework.web: DEBUG
--------------------------------------------------------------------------------
/spring-cloud-config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-config-server
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.config.server.ConfigServerApplication
17 | spring-cloud-demo
18 |
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-config-server
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-maven-plugin
38 |
39 |
40 | com.spotify
41 | docker-maven-plugin
42 | 0.4.11
43 |
44 | ${docker.image.prefix}/${project.artifactId}
45 | src/main/docker
46 |
47 |
48 | /
49 | ${project.build.directory}
50 | ${project.build.finalName}.jar
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM frolvlad/alpine-oraclejdk8:slim
2 | VOLUME /tmp
3 | ADD spring-cloud-config-server-1.0-SNAPSHOT.jar app.jar
4 | RUN sh -c 'touch /app.jar'
5 | ENV JAVA_OPTS=""
6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/java/com/zzqfsy/cloud/config/server/ConfigServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.config.server;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | /**
8 | * Created by john on 16-10-17.
9 | */
10 | @SpringBootApplication
11 | @EnableConfigServer
12 | public class ConfigServerApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(ConfigServerApplication.class, args);
15 | }
16 | }
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | servers:
2 | jpushCenter:
3 | host: http://127.0.0.1:8073/jpush/send/
4 | title: server-云端钱包测试版
5 | destination: server-ydWalletTest
6 |
7 | apply:
8 | message: server-local message
9 |
10 | logging:
11 | levels:
12 | org.springframework.boot.env.PropertySourcesLoader: TRACE
13 | org.springframework.web: DEBUG
14 | org.springframework.cloud: DEBUG
15 |
16 | spring:
17 | cloud:
18 | config:
19 | server:
20 | git:
21 | uri: https://github.com/zzqfsy/config-repo
22 | # username:
23 | # password:
24 | repos:
25 | - patterns: multi-repo-demo-*
26 | uri: https://github.com/zzqfsy/config-repo
27 | health:
28 | repositories:
29 | myservice-dev:
30 | name: application
31 | profiles: dev
32 | encrypt:
33 | enabled: true
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-cloud-config-server/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8060
3 | spring:
4 | application:
5 | name: configserver
6 | cloud:
7 | config:
8 | enabled: true
9 | uri: http://127.0.0.1:8060
10 | profile: dev
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-eureka-client
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.eureka.client.EurekaClientApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-eureka
29 |
30 |
31 | org.springframework.cloud
32 | spring-cloud-config-client
33 |
34 |
35 | org.springframework.cloud
36 | spring-cloud-starter-hystrix
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-hystrix-dashboard
41 |
42 |
43 | org.springframework.cloud
44 | spring-cloud-starter-feign
45 |
46 |
47 | org.springframework.cloud
48 | spring-cloud-starter-ribbon
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-actuator
53 |
54 |
55 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/EurekaClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client;
2 |
3 | import com.netflix.discovery.DiscoveryClient;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
9 | import org.springframework.cloud.netflix.feign.EnableFeignClients;
10 | import org.springframework.cloud.netflix.hystrix.EnableHystrix;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.web.client.RestTemplate;
13 |
14 | /**
15 | * Created by john on 16-10-17.
16 | */
17 | @SpringBootApplication
18 | @EnableEurekaClient
19 | @EnableFeignClients
20 | @EnableCircuitBreaker
21 | @EnableHystrix
22 | public class EurekaClientApplication {
23 | /* @Bean
24 | @LoadBalanced
25 | RestTemplate restTemplate() {
26 | return new RestTemplate();
27 | }*/
28 |
29 | public static void main(String[] args) {
30 | SpringApplication.run(EurekaClientApplication.class, args);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/controller/CompanyController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.client.rpc.failure.ComandCompanyFailure;
4 | import com.zzqfsy.cloud.eureka.client.rpc.failure.ComandCompanyObservableFailure;
5 | import com.zzqfsy.cloud.eureka.client.rpc.hytrix.CompanyHystrixWrappedClient;
6 | import com.zzqfsy.cloud.eureka.client.model.Company;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.PathVariable;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RequestMethod;
11 | import org.springframework.web.bind.annotation.RestController;
12 | import rx.Observable;
13 |
14 | import java.util.concurrent.ExecutionException;
15 | import java.util.concurrent.Future;
16 |
17 | /**
18 | * Created by john on 16-10-20.
19 | */
20 | @RestController
21 | @RequestMapping("/api")
22 | public class CompanyController {
23 | @Autowired
24 | CompanyHystrixWrappedClient companyHystrixWrappedClient;
25 |
26 | @RequestMapping("/companys")
27 | public Company getCompanys(){
28 | return companyHystrixWrappedClient.getCompanys();
29 | }
30 |
31 | @RequestMapping("/companys1")
32 | public Company getCompanys1(){
33 | return companyHystrixWrappedClient.getCompanys1();
34 | }
35 |
36 | @RequestMapping("/companys2")
37 | public Company getCompanys2(){
38 | return companyHystrixWrappedClient.getCompanys2();
39 | }
40 |
41 | @RequestMapping("/companysFutureCollapser")
42 | public Company getCompanysFutureCollapser(){
43 | Future companyFuture = companyHystrixWrappedClient.getCompanyByIdAsync("1");
44 | try {
45 | return companyFuture.get();
46 | } catch (InterruptedException | ExecutionException e) {
47 | e.printStackTrace();
48 | }
49 | return null;
50 | }
51 |
52 |
53 | @RequestMapping("/companysFuture")
54 | public Company getCompanysFuture(){
55 | Future companyFuture = companyHystrixWrappedClient.getCompanysFuture();
56 | try {
57 | return companyFuture.get();
58 | } catch (InterruptedException | ExecutionException e) {
59 | e.printStackTrace();
60 | }
61 | return null;
62 | }
63 |
64 | @RequestMapping("/companysObservableCollapser")
65 | public Company getCompanysObservableCollapser(){
66 | Observable companyObservable = companyHystrixWrappedClient.getCompanyByIdReact("1");
67 | return companyObservable.toBlocking().single();
68 | }
69 |
70 | @RequestMapping("/companysObservable")
71 | public Company getCompanysObservable(){
72 | Observable companyObservable = companyHystrixWrappedClient.getCompanysObservable();
73 | return companyObservable.toBlocking().single();
74 | }
75 |
76 | @RequestMapping("/company/{id}")
77 | public Company getCompanyById(@PathVariable("id") Long id){
78 | return companyHystrixWrappedClient.getCompanyById(id);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/controller/EmployeeController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.client.model.Employee;
4 | import com.zzqfsy.cloud.eureka.client.rpc.hytrix.EmployeeHystrixClient;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by john on 16-10-28.
13 | */
14 | @RestController
15 | @RequestMapping("/api")
16 | public class EmployeeController {
17 | @Autowired
18 | EmployeeHystrixClient employeeHystrixClient;
19 |
20 | @RequestMapping("/employees/1")
21 | public Employee getEmployeeById(){
22 | return employeeHystrixClient.getEmployeeById(1L);
23 | }
24 |
25 | @RequestMapping("/employees")
26 | public List getEmployeeByIds(){
27 | return employeeHystrixClient.getEmployeeByIds(1L);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.client.rpc.failure.ComandCompanyFailure;
4 | import com.zzqfsy.cloud.eureka.client.rpc.failure.ComandCompanyObservableFailure;
5 | import com.zzqfsy.cloud.eureka.client.rpc.feign.HelloFeignClient;
6 | import com.zzqfsy.cloud.eureka.client.rpc.hytrix.HelloHystrixWrappedClient;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 | import rx.Observable;
11 | import rx.Observer;
12 | import rx.functions.Action1;
13 |
14 | import java.util.concurrent.ExecutionException;
15 | import java.util.concurrent.Future;
16 |
17 | /**
18 | * Created by john on 16-10-28.
19 | */
20 | @RestController
21 | @RequestMapping("/api")
22 | public class HelloController {
23 |
24 | @Autowired
25 | HelloFeignClient client;
26 |
27 | @Autowired
28 | HelloHystrixWrappedClient hytrixClient;
29 |
30 | /**
31 | * 直接调用feign,feign会去调用eurekaService
32 | * */
33 | @RequestMapping("/")
34 | public String hello() {
35 | return client.hello();
36 | }
37 |
38 | /**
39 | * 1、调用hytrix
40 | * 2、hytrix继承并调用feign
41 | * 3、feign会去调用eurekaService
42 | * */
43 | @RequestMapping("/hytrix")
44 | public String hytrixHello() {
45 | return hytrixClient.hello();
46 | }
47 |
48 |
49 | @RequestMapping("/hytrix2")
50 | public String hytrixHello2() {
51 | return new ComandCompanyFailure("ComandCompanyObservableFailure").execute();
52 | }
53 |
54 | @RequestMapping("/hytrix3")
55 | public String hytrixHello3() {
56 | Future fs = new ComandCompanyFailure("ComandCompanyObservableFailure").queue();
57 | try {
58 | return fs.get();
59 | } catch (InterruptedException | ExecutionException e) {
60 | e.printStackTrace();
61 | }
62 |
63 | return "";
64 | }
65 |
66 | @RequestMapping("/hytrix4")
67 | public String hytrixHello4() {
68 | Observable ho = new ComandCompanyObservableFailure("ComandCompanyObservableFailure").observe();
69 | ho.subscribe(new Observer() {
70 | @Override
71 | public void onCompleted() {
72 | System.out.println("Then onCompleted.");
73 | }
74 | @Override
75 | public void onError(Throwable e) {
76 | System.out.println("Then onError.");
77 | e.printStackTrace();
78 | }
79 | @Override
80 | public void onNext(String v) {
81 | System.out.println("Then onNext: " + v);
82 | }
83 | });
84 |
85 | ho.subscribe(new Action1() {
86 |
87 | @Override
88 | public void call(String s) {
89 | System.out.println("Then called.");
90 | }
91 | });
92 |
93 | return ho.toBlocking().single();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/controller/ProductController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.client.rpc.hytrix.ProductHystrixWrappedClient;
4 | import com.zzqfsy.cloud.eureka.client.model.Product;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by john on 16-10-21.
15 | */
16 | @RestController
17 | @RequestMapping("/api")
18 | public class ProductController {
19 | @Autowired
20 | ProductHystrixWrappedClient productHystrixWrappedClient;
21 |
22 | @RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
23 | Product getProductById(@PathVariable("id") Long id){
24 | return productHystrixWrappedClient.getProductById(id);
25 | }
26 |
27 | @RequestMapping(value = "/product", method = RequestMethod.GET)
28 | List getProductsByCompanyId(){
29 | return productHystrixWrappedClient.getProductsByCompanyId(20L);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/model/Company.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Company {
7 | private Long id;
8 | private String name;
9 |
10 | public Company() {
11 | }
12 |
13 | public Company(Long id, String name) {
14 | this.id = id;
15 | this.name = name;
16 | }
17 |
18 | public Long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(Long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/model/Employee.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Employee {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String name;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Employee() {
15 | }
16 |
17 | public Employee(Long id, Long companyId, String name) {
18 | this.id = id;
19 | this.companyId = companyId;
20 | this.name = name;
21 | }
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public Long getCompanyId() {
32 | return companyId;
33 | }
34 |
35 | public void setCompanyId(Long companyId) {
36 | this.companyId = companyId;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 | }
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/model/OneCompany.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.model;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by john on 16-10-28.
7 | */
8 | public class OneCompany {
9 | Company company;
10 | List employees;
11 | List products;
12 |
13 | public OneCompany() {
14 | }
15 |
16 | public OneCompany(
17 | Company company,
18 | List employees,
19 | List products
20 | ) {
21 | this.company = company;
22 | this.employees = employees;
23 | this.products = products;
24 | }
25 |
26 | public Company getCompany() {
27 | return company;
28 | }
29 |
30 | public void setCompany(Company company) {
31 | this.company = company;
32 | }
33 |
34 | public List getEmployees() {
35 | return employees;
36 | }
37 |
38 | public void setEmployees(List employees) {
39 | this.employees = employees;
40 | }
41 |
42 | public List getProducts() {
43 | return products;
44 | }
45 |
46 | public void setProducts(List products) {
47 | this.products = products;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Product {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String sku;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Product() {
15 | }
16 |
17 | public Product(Long id, Long companyId, String sku) {
18 | this.id = id;
19 | this.companyId = companyId;
20 | this.sku = sku;
21 | }
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public Long getCompanyId() {
32 | return companyId;
33 | }
34 |
35 | public void setCompanyId(Long companyId) {
36 | this.companyId = companyId;
37 | }
38 |
39 | public String getSku() {
40 | return sku;
41 | }
42 |
43 | public void setSku(String sku) {
44 | this.sku = sku;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/failure/ComandCompanyFailure.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.failure;
2 |
3 | import com.netflix.hystrix.HystrixCommand;
4 | import com.netflix.hystrix.HystrixCommandGroupKey;
5 | import com.netflix.hystrix.HystrixCommandKey;
6 | import com.netflix.hystrix.HystrixThreadPoolKey;
7 | import rx.Observable;
8 | import rx.Subscriber;
9 |
10 | /**
11 | * Created by john on 16-10-27.
12 | */
13 | public class ComandCompanyFailure extends HystrixCommand {
14 |
15 | private final String name;
16 |
17 | public ComandCompanyFailure(String name) {
18 | super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
19 | .andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorld"))
20 | .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("HelloWorldPool")));
21 | this.name = name;
22 | }
23 |
24 | @Override
25 | protected String run() {
26 | return "Company";
27 | }
28 |
29 | @Override
30 | protected String getFallback() {
31 | return "Company " + name + "!";
32 | }
33 | }
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/failure/ComandCompanyObservableFailure.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.failure;
2 |
3 | import com.netflix.hystrix.HystrixCommandGroupKey;
4 | import com.netflix.hystrix.HystrixObservableCommand;
5 | import rx.Observable;
6 | import rx.Subscriber;
7 |
8 | /**
9 | * Created by john on 16-10-27.
10 | */
11 | public class ComandCompanyObservableFailure extends HystrixObservableCommand {
12 |
13 | private final String name;
14 |
15 | public ComandCompanyObservableFailure(String name) {
16 | super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
17 | this.name = name;
18 | }
19 |
20 | @Override
21 | protected Observable construct() {
22 | return Observable.create(new Observable.OnSubscribe() {
23 | @Override
24 | public void call(Subscriber super String> observer) {
25 | try {
26 | if (!observer.isUnsubscribed()) {
27 | // a real example would do work like a network call here
28 | observer.onNext("Hello");
29 | observer.onNext(name + "!");
30 | observer.onCompleted();
31 | }
32 | } catch (Exception e) {
33 | observer.onError(e);
34 | }
35 | }
36 | } );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/feign/CompanyFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.feign;
2 |
3 | import com.zzqfsy.cloud.eureka.client.model.Company;
4 | import org.springframework.cloud.netflix.feign.FeignClient;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 |
8 | /**
9 | * Created by john on 16-10-21.
10 | */
11 | @FeignClient("eurekaservice1")
12 | public interface CompanyFeignClient {
13 | @RequestMapping("/api/companys/")
14 | public Company getCompanys();
15 |
16 | @RequestMapping("/api/companys/{id}")
17 | public Company getCompanyById(@PathVariable("id") Long id);
18 | }
19 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/feign/EmployeeFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.feign;
2 |
3 | import com.zzqfsy.cloud.eureka.client.model.Employee;
4 | import org.springframework.cloud.netflix.feign.FeignClient;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by john on 16-10-28.
13 | */
14 | @FeignClient("eurekadashboard")
15 | public interface EmployeeFeignClient {
16 | @RequestMapping("/api/employees/{id}")
17 | Employee getEmployeeById(@PathVariable("id") Long id);
18 |
19 | @RequestMapping("/api/employees/")
20 | List getEmployeesByCompanyId(@RequestParam("companyId") Long companyId);
21 | }
22 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/feign/HelloFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.feign;
2 |
3 | import org.springframework.cloud.netflix.feign.FeignClient;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | import static org.springframework.web.bind.annotation.RequestMethod.GET;
7 |
8 | /**
9 | * Created by john on 16-10-17.
10 | */
11 |
12 | @FeignClient("eurekaservice1")
13 | public interface HelloFeignClient {
14 | @RequestMapping(value = "/hello", method = GET)
15 | String hello();
16 | }
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/feign/ProductFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.feign;
2 |
3 | import com.zzqfsy.cloud.eureka.client.model.Product;
4 | import org.springframework.cloud.netflix.feign.FeignClient;
5 | import org.springframework.http.MediaType;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by john on 16-10-21.
15 | */
16 | @FeignClient("eureka-server")
17 | public interface ProductFeignClient {
18 | @RequestMapping(value = "/api/products/{id}", method = RequestMethod.GET)
19 | Product getProductById(@PathVariable("id") Long id);
20 |
21 | @RequestMapping(value = "/api/products/", method = RequestMethod.GET,
22 | produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
23 | List getProductsByCompanyId(@RequestParam("companyId") Long companyId);
24 | }
25 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/hytrix/CompanyHystrixWrappedClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
4 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
5 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
6 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
7 | import com.netflix.hystrix.contrib.javanica.command.AsyncResult;
8 | import com.zzqfsy.cloud.eureka.client.rpc.feign.CompanyFeignClient;
9 | import com.zzqfsy.cloud.eureka.client.model.Company;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.stereotype.Service;
12 | import rx.Observable;
13 | import rx.Subscriber;
14 |
15 | import java.util.Arrays;
16 | import java.util.List;
17 | import java.util.concurrent.Future;
18 |
19 | /**
20 | * Created by john on 16-10-21.
21 | */
22 | @Service("companyHystrixWrappedClient")
23 | public class CompanyHystrixWrappedClient {
24 | @Autowired
25 | private CompanyFeignClient companyFeignClient;
26 |
27 | @HystrixCommand(groupKey = "eurekaservice1", fallbackMethod = "fallBackCall")
28 | public Company getCompanyById(Long id) {
29 | return companyFeignClient.getCompanyById(id);
30 | }
31 |
32 | public Company fallBackCall(Long id) {
33 | return new Company(id, "FAILED SERVICE CALL! - FALLING BACK");
34 | }
35 |
36 | @HystrixCommand(fallbackMethod = "fallBackCall")
37 | public Company getCompanys() {
38 | return companyFeignClient.getCompanys();
39 | }
40 |
41 | @HystrixCommand(groupKey = "eurekaservice1", fallbackMethod = "fallBackCall")
42 | public Company getCompanys1() {
43 | return companyFeignClient.getCompanys();
44 | }
45 |
46 | @HystrixCommand(commandProperties = {
47 | @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
48 | }, threadPoolProperties = {
49 | @HystrixProperty(name = "coreSize", value = "30"),
50 | @HystrixProperty(name = "maxQueueSize", value = "101"),
51 | @HystrixProperty(name = "keepAliveTimeMinutes", value = "2"),
52 | @HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"),
53 | @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
54 | @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
55 | }, fallbackMethod = "fallBackCall")
56 | public Company getCompanys2() {
57 | return companyFeignClient.getCompanys();
58 | }
59 |
60 |
61 | @HystrixCommand(groupKey = "eurekaservice1", fallbackMethod = "fallBackCallList")
62 | public List getCompanyByIds(String id) {
63 | return Arrays.asList(companyFeignClient.getCompanys());
64 | }
65 |
66 |
67 | /** Asynchronous Execution */
68 | @HystrixCollapser(batchMethod = "getCompanyByIds")
69 | public Future getCompanyByIdAsync(String id) {
70 | return null;
71 | }
72 | @HystrixCommand(groupKey = "eurekaservice1", fallbackMethod = "fallBackCall")
73 | public Future getCompanysFuture() {
74 | return new AsyncResult() {
75 | @Override
76 | public Company invoke() {
77 | return companyFeignClient.getCompanys();
78 | }
79 | };
80 | }
81 |
82 | /** Reactive Execution */
83 | @HystrixCollapser(batchMethod = "getCompanyByIds")
84 | public Observable getCompanyByIdReact(String id) {
85 | return null;
86 | }
87 | @HystrixCommand(groupKey = "eurekaservice1", fallbackMethod = "fallBackCall")
88 | public Observable getCompanysObservable() {
89 | return Observable.create(new Observable.OnSubscribe() {
90 | @Override
91 | public void call(Subscriber super Company> observer) {
92 | try {
93 | if (!observer.isUnsubscribed()) {
94 | observer.onNext(companyFeignClient.getCompanys());
95 | observer.onCompleted();
96 | }
97 | } catch (Exception e) {
98 | observer.onError(e);
99 | }
100 | }
101 | });
102 | }
103 |
104 | public Company fallBackCall() {
105 | return new Company(1L, "FAILED SERVICE CALL! - FALLING BACK");
106 | }
107 |
108 | public List fallBackCallList() {
109 | return Arrays.asList(new Company(1L, "FAILED SERVICE CALL! - FALLING BACK"));
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/hytrix/EmployeeHystrixClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.zzqfsy.cloud.eureka.client.model.Employee;
5 | import com.zzqfsy.cloud.eureka.client.rpc.feign.EmployeeFeignClient;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by john on 16-10-28.
14 | */
15 | @Service("employeeHystrixClient")
16 | public class EmployeeHystrixClient {
17 | @Autowired
18 | EmployeeFeignClient employeeFeignClient;
19 |
20 | @HystrixCommand(groupKey = "eurekadashboard", fallbackMethod = "fallBackCall")
21 | public Employee getEmployeeById(Long companyId) {
22 | return employeeFeignClient.getEmployeeById(companyId);
23 | }
24 |
25 | @HystrixCommand(groupKey = "eurekadashboard", fallbackMethod = "fallBackCallList")
26 | public List getEmployeeByIds(Long companyId) {
27 | return employeeFeignClient.getEmployeesByCompanyId(companyId);
28 | }
29 |
30 |
31 | Employee fallBackCall(Long companyId){
32 | return new Employee(0L, 0L, "error");
33 | }
34 |
35 | List fallBackCallList(Long companyId){
36 | return Arrays.asList(new Employee(0L, 0L, "error"));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/hytrix/HelloHystrixWrappedClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
5 | import com.zzqfsy.cloud.eureka.client.rpc.feign.HelloFeignClient;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | @Service("hystrixHelloClient")
10 | public class HelloHystrixWrappedClient {
11 |
12 | @Autowired
13 | private HelloFeignClient helloFeignClient;
14 |
15 | @HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall")
16 | public String hello() {
17 | return this.helloFeignClient.hello();
18 | }
19 |
20 | public String fallBackCall() {
21 | return "FAILED SERVICE CALL! - FALLING BACK";
22 | }
23 |
24 | /*@HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall",
25 | commandProperties = {
26 | @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
27 | },
28 | threadPoolProperties = {
29 | @HystrixProperty(name = "coreSize", value = "30"),
30 | @HystrixProperty(name = "maxQueueSize", value = "101"),
31 | @HystrixProperty(name = "keepAliveTimeMinutes", value = "2"),
32 | @HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"),
33 | @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
34 | @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
35 | })
36 | public String helloRibbon() {
37 | return this.helloFeignClient.hello();
38 | }*/
39 | }
40 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/hytrix/ProductHystrixWrappedClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.zzqfsy.cloud.eureka.client.rpc.feign.ProductFeignClient;
5 | import com.zzqfsy.cloud.eureka.client.model.Product;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by john on 16-10-21.
14 | */
15 | @Service("productHystrixHelloClient")
16 | public class ProductHystrixWrappedClient {
17 | @Autowired
18 | private ProductFeignClient productFeignClient;
19 |
20 | @HystrixCommand(groupKey = "productGroup", fallbackMethod = "fallBackCall")
21 | public Product getProductById(Long id) {
22 | return productFeignClient.getProductById(id);
23 | }
24 |
25 | @HystrixCommand(groupKey = "productGroup2", fallbackMethod = "fallBackCallList")
26 | public List getProductsByCompanyId(Long companyId) {
27 | return productFeignClient.getProductsByCompanyId(companyId);
28 | }
29 |
30 | public Product fallBackCall(Long id) {
31 | return new Product(id, id, "FAILED SERVICE CALL! - FALLING BACK");
32 | }
33 |
34 | public List fallBackCallList(Long id) {
35 | return Arrays.asList(new Product(id, id, "FAILED SERVICE CALL! - FALLING BACK"));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/java/com/zzqfsy/cloud/eureka/client/rpc/ribbon/HelloRibbonClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.client.rpc.ribbon;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 |
5 | import static org.springframework.web.bind.annotation.RequestMethod.GET;
6 |
7 | /**
8 | * Created by john on 16-10-19.
9 | */
10 | //@RibbonClient("eurekaservice")
11 | public interface HelloRibbonClient {
12 | @RequestMapping(value = "/hello", method = GET)
13 | String hello();
14 | }
15 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8051
3 | eureka:
4 | instance:
5 | appname: eurekaclient1
6 | leaseRenewalIntervalInSeconds: 10
7 | metadataMap:
8 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
9 |
10 | client:
11 | registerWithEureka: true
12 | fetchRegistry: true
13 | serviceUrl:
14 | defaultZone: http://127.0.0.1:8061/eureka/
15 | #http://eurekaserver10:8061/eureka/,http://eurekaserver20:8071/eureka/,http://eurekaserver30:8081/eureka/
16 |
17 | #spring:
18 | # cloud:
19 | # config:
20 | # discovery:
21 | # enabled: true
22 | # service-id: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
23 |
24 | hystrix:
25 | command:
26 | default:
27 | execution:
28 | isolation:
29 | thread:
30 | timeoutInMilliseconds: 5000
31 | # getCompanys:
32 | # execution:
33 | # isolation:
34 | # thread:
35 | # timeoutInMilliseconds: 5000
36 |
37 | #eurekaservice1:
38 | # ribbon:
39 | # MaxAutoRetries: 2
40 | # ConnectTimeout: 5000
41 | # ReadTimeout: 10000
42 | # OkToRetryOnAllOperations: true
43 | # EnableGZIPContentEncodingFilter: true
44 |
45 | #feign:
46 | # hystrix:
47 | # enabled: true
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-cloud-eureka-client/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: eurekaclient1
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 | label: master
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-eureka-dashboard
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.eureka.dashboard.EurekaDashboardApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.cloud
27 | spring-cloud-config-client
28 |
29 |
30 | org.springframework.cloud
31 | spring-cloud-starter-hystrix-dashboard
32 |
33 |
34 | org.springframework.cloud
35 | spring-cloud-starter-turbine
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-actuator
40 |
41 |
42 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/java/com.zzqfsy.cloud.eureka.dashboard/EurekaDashboardApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.dashboard;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
7 | import org.springframework.cloud.netflix.turbine.EnableTurbine;
8 |
9 | /**
10 | * Created by john on 16-10-18.
11 | */
12 | @SpringBootApplication
13 | @EnableEurekaClient
14 | @EnableHystrixDashboard
15 | @EnableTurbine
16 | public class EurekaDashboardApplication {
17 | public static void main(String[] args) {
18 | SpringApplication.run(EurekaDashboardApplication.class, args);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/java/com.zzqfsy.cloud.eureka.dashboard/controller/EmployeeController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.dashboard.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.dashboard.model.Employee;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import java.util.Random;
12 |
13 | /**
14 | * Created by john on 16-10-20.
15 | */
16 | @RestController
17 | @RequestMapping("/api/employees")
18 | public class EmployeeController {
19 |
20 | @RequestMapping("/{id}")
21 | public Employee getEmployeeById(@PathVariable("id") Long id) {
22 | sleep();
23 | return new Employee(id,1L,"张三");
24 | }
25 |
26 | @RequestMapping("/")
27 | public List getEmployeesByCompanyId(@RequestParam("companyId") Long companyId){
28 | List employees = new ArrayList<>();
29 |
30 | employees.add(new Employee(1L, companyId, "张三"));
31 | employees.add(new Employee(2L, companyId, "李四"));
32 | employees.add(new Employee(3L, companyId, "王五"));
33 |
34 | sleep();
35 | return employees;
36 | }
37 |
38 | private void sleep() {
39 | Random rand = new Random();
40 | int time = rand.nextInt(2000);
41 |
42 | try {
43 | Thread.sleep(time);
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/java/com.zzqfsy.cloud.eureka.dashboard/model/Employee.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.dashboard.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Employee {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String name;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Employee(Long id, Long companyId, String name) {
15 | this.id = id;
16 | this.companyId = companyId;
17 | this.name = name;
18 | }
19 |
20 | public Long getId() {
21 | return id;
22 | }
23 |
24 | public void setId(Long id) {
25 | this.id = id;
26 | }
27 |
28 | public Long getCompanyId() {
29 | return companyId;
30 | }
31 |
32 | public void setCompanyId(Long companyId) {
33 | this.companyId = companyId;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 | }
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8063
3 | eureka:
4 | instance:
5 | appname: eurekadashboard
6 | leaseRenewalIntervalInSeconds: 10
7 | metadataMap:
8 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
9 | client:
10 | registerWithEureka: true
11 | fetchRegistry: true
12 | serviceUrl:
13 | defaultZone: http://127.0.0.1:8061/eureka/
14 |
15 | #turbine:
16 | # aggregator:
17 | # clusterConfig: eurekaclient
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-cloud-eureka-dashboard/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: eurekadashboard #eurekaservice
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 | label: master
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-eureka-server
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.eureka.server.EurekaServerApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-eureka-server
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-actuator
33 |
34 |
35 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/java/com/zzqfsy/cloud/eureka/server/EurekaServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.server;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.builder.SpringApplicationBuilder;
6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
7 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
8 |
9 | /**
10 | * Created by john on 16-10-17.
11 | */
12 | @SpringBootApplication
13 | @EnableEurekaServer
14 | @EnableEurekaClient
15 | public class EurekaServerApplication {
16 |
17 | /*@Bean
18 | DiscoveryClient.DiscoveryClientOptionalArgs discoveryClientOptionalArgs(){
19 | return new DiscoveryClient.DiscoveryClientOptionalArgs();
20 | }*/
21 |
22 | public static void main(String[] args) {
23 | //SpringApplication.run(EurekaServerApplication.class, args);
24 | new SpringApplicationBuilder(EurekaServerApplication.class).web(true).run(args);
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/java/com/zzqfsy/cloud/eureka/server/controller/ProductController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.server.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.server.model.Product;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Random;
15 |
16 | /**
17 | * Created by john on 16-10-20.
18 | */
19 | @RestController
20 | @RequestMapping(value = "/api/products")
21 | public class ProductController {
22 |
23 | private static final Logger LOG = LoggerFactory.getLogger(ProductController.class);
24 |
25 | @RequestMapping(value = "/{id}", method = RequestMethod.GET)
26 | public Product getProductById(@PathVariable("id") Long id) {
27 | //sleep();
28 | return new Product(id, 1L, "T001");
29 | }
30 |
31 |
32 | @RequestMapping(value = "/", method = RequestMethod.GET)
33 | public List getProductsByCompanyId(@RequestParam("companyId") Long companyId) {
34 | List products = new ArrayList<>();
35 |
36 | products.add(new Product(1L, companyId, "T001"));
37 | products.add(new Product(2L, companyId, "T002"));
38 | products.add(new Product(3L, companyId, "T003"));
39 | return products;
40 | }
41 |
42 |
43 | private void sleep() {
44 | Random rand = new Random();
45 | int time = rand.nextInt(3000);
46 |
47 | try {
48 | Thread.sleep(time);
49 | } catch (Exception e) {
50 | e.printStackTrace();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/java/com/zzqfsy/cloud/eureka/server/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.server.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Product {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String sku;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Product(Long id, Long companyId, String sku) {
15 | this.id = id;
16 | this.companyId = companyId;
17 | this.sku = sku;
18 | }
19 |
20 | public Long getId() {
21 | return id;
22 | }
23 |
24 | public void setId(Long id) {
25 | this.id = id;
26 | }
27 |
28 | public Long getCompanyId() {
29 | return companyId;
30 | }
31 |
32 | public void setCompanyId(Long companyId) {
33 | this.companyId = companyId;
34 | }
35 |
36 | public String getSku() {
37 | return sku;
38 | }
39 |
40 | public void setSku(String sku) {
41 | this.sku = sku;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/application-backup.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8071
3 |
4 | eureka:
5 | instance:
6 | #preferIpAddress: true
7 | hostname: eurekaserver20
8 | appname: eureka-server
9 | statusPageUrlPath: ${management.context-path}/info
10 | healthCheckUrlPath: ${management.context-path}/health
11 | # statusPageUrl: http://${eureka.hostname}/info
12 | # healthCheckUrl: http://${eureka.hostname}/health
13 | # homePageUrl: http://${eureka.hostname}/home
14 | client:
15 | # registerWithEureka: false
16 | # fetchRegistry: false
17 | # serviceUrl:
18 | # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
19 | serviceUrl:
20 | defaultZone: http://eurekaserver10:8061/eureka/,http://eurekaserver30:8081/eureka/
21 |
22 | management:
23 | context-path: /manager
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8061
3 |
4 | eureka:
5 | instance:
6 | hostname: eurekaserver10
7 | appname: eureka-server
8 | statusPageUrlPath: ${management.context-path}/info
9 | healthCheckUrlPath: ${management.context-path}/health
10 | # statusPageUrl: http://${eureka.hostname}/info
11 | # healthCheckUrl: http://${eureka.hostname}/health
12 | # homePageUrl: http://${eureka.hostname}/home
13 | client:
14 | # registerWithEureka: true
15 | # fetchRegistry: true
16 | serviceUrl:
17 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
18 |
19 | management:
20 | context-path: /manager
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/application-master.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8061
3 |
4 | eureka:
5 | instance:
6 | hostname: eurekaserver10
7 | appname: eureka-server
8 | statusPageUrlPath: ${management.context-path}/info
9 | healthCheckUrlPath: ${management.context-path}/health
10 | # statusPageUrl: http://${eureka.hostname}/info
11 | # healthCheckUrl: http://${eureka.hostname}/health
12 | # homePageUrl: http://${eureka.hostname}/home
13 | client:
14 | # registerWithEureka: false
15 | # fetchRegistry: false
16 | # serviceUrl:
17 | # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
18 | serviceUrl:
19 | defaultZone: http://eurekaserver20:8071/eureka/,http://eurekaserver30:8081/eureka/
20 |
21 |
22 |
23 | management:
24 | context-path: /manager
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/application-secondary.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 |
4 | eureka:
5 | instance:
6 | #preferIpAddress: true
7 | hostname: eurekaserver30
8 | appname: eureka-server
9 | statusPageUrlPath: ${management.context-path}/info
10 | healthCheckUrlPath: ${management.context-path}/health
11 | # statusPageUrl: http://${eureka.hostname}/info
12 | # healthCheckUrl: http://${eureka.hostname}/health
13 | # homePageUrl: http://${eureka.hostname}/home
14 | client:
15 | # registerWithEureka: false
16 | # fetchRegistry: false
17 | # serviceUrl:
18 | # defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
19 | serviceUrl:
20 | defaultZone: http://eurekaserver10:8061/eureka/,http://eurekaserver20:8071/eureka/
21 |
22 | management:
23 | context-path: /manager
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
4 |
5 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-server/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: eureka-server
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-eureka-service
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.eureka.service.EurekaServiceApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-eureka
29 |
30 |
31 | org.springframework.cloud
32 | spring-cloud-config-client
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-actuator
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-hystrix
41 |
42 |
43 | org.springframework.cloud
44 | spring-cloud-starter-feign
45 |
46 |
47 | org.springframework.cloud
48 | spring-cloud-starter-ribbon
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/EurekaServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.ServiceInstance;
7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
8 | import org.springframework.cloud.client.discovery.DiscoveryClient;
9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10 | import org.springframework.cloud.netflix.feign.EnableFeignClients;
11 | import org.springframework.cloud.netflix.hystrix.EnableHystrix;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 |
14 | /**
15 | * Created by john on 16-10-17.
16 | */
17 | @SpringBootApplication
18 | @EnableDiscoveryClient
19 | @EnableFeignClients
20 | @EnableCircuitBreaker
21 | @EnableHystrix
22 | public class EurekaServiceApplication {
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(EurekaServiceApplication.class, args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/api/resp/BaseResp.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.api.resp;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by john on 16-7-6.
7 | */
8 | public class BaseResp implements Serializable {
9 |
10 | private String code;
11 |
12 | private T result;
13 |
14 | private Integer errorType;
15 |
16 | private String errorMsg;
17 |
18 | private boolean isSuccess = true;
19 |
20 | public BaseResp() {
21 | }
22 |
23 | public BaseResp(String code, T result, Integer errorType, String errorMsg, boolean isSuccess) {
24 | this.code = code;
25 | this.result = result;
26 | this.errorType = errorType;
27 | this.errorMsg = errorMsg;
28 | this.isSuccess = isSuccess;
29 | }
30 |
31 | public static BaseResp create(Object result){
32 | return new BaseResp("0", result, 0, "正常", true);
33 | }
34 |
35 | public String getCode() {
36 | return code;
37 | }
38 |
39 | public void setCode(String code) {
40 | this.code = code;
41 | }
42 |
43 | public T getResult() {
44 | return result;
45 | }
46 |
47 | public void setResult(T result) {
48 | this.result = result;
49 | }
50 |
51 | public Integer getErrorType() {
52 | return errorType;
53 | }
54 |
55 | public void setErrorType(Integer errorType) {
56 | this.errorType = errorType;
57 | }
58 |
59 | public String getErrorMsg() {
60 | return errorMsg;
61 | }
62 |
63 | public void setErrorMsg(String errorMsg) {
64 | this.errorMsg = errorMsg;
65 | }
66 |
67 | public boolean isSuccess() {
68 | return isSuccess;
69 | }
70 |
71 | public void setSuccess(boolean success) {
72 | isSuccess = success;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/controller/CompanyController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.controller;
2 |
3 | import com.zzqfsy.cloud.eureka.service.api.resp.BaseResp;
4 | import com.zzqfsy.cloud.eureka.service.model.Company;
5 | import com.zzqfsy.cloud.eureka.service.model.OneCompany;
6 | import com.zzqfsy.cloud.eureka.service.rpc.hytrix.EmployeeHystrixClient;
7 | import com.zzqfsy.cloud.eureka.service.rpc.hytrix.ProductHystrixClient;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 | import org.springframework.web.bind.annotation.RequestParam;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | import java.util.Random;
16 |
17 | /**
18 | * Created by john on 16-10-20.
19 | */
20 | @RestController
21 | @RequestMapping(value = "/api/companys")
22 | public class CompanyController {
23 |
24 | @Autowired
25 | EmployeeHystrixClient employeeHystrixClient;
26 | @Autowired
27 | ProductHystrixClient productHystrixClient;
28 |
29 | @RequestMapping("/{id}")
30 | public Company getCompanyById(@PathVariable("id") Long id){
31 | //sleep();
32 | return new Company(id, "Company");
33 | }
34 |
35 | @RequestMapping(value = "/", method = RequestMethod.GET)
36 | public Company getCompanys(){
37 | sleep();
38 | return new Company(1L, "Company");
39 | }
40 |
41 | @RequestMapping(value = "/", method = RequestMethod.POST)
42 | public BaseResp createCompanys(@RequestParam("companyId") Long companyId){
43 | OneCompany oneCompany = new OneCompany();
44 | oneCompany.setCompany(new Company(companyId, "Company"));
45 | oneCompany.setEmployees(employeeHystrixClient.getEmployeeByIds(companyId));
46 | oneCompany.setProducts(productHystrixClient.getProductsByCompanyId(companyId));
47 | return BaseResp.create(oneCompany);
48 | }
49 |
50 |
51 | //利用时间等待模拟Serivce调用时长
52 | private void sleep() {
53 | Random rand = new Random();
54 | int time = rand.nextInt(2000);
55 |
56 | try {
57 | Thread.sleep(2000);
58 | } catch (Exception e) {
59 | e.printStackTrace();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/controller/ServiceController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.controller;
2 |
3 | import com.netflix.appinfo.InstanceInfo;
4 | import com.netflix.discovery.EurekaClient;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.cloud.client.ServiceInstance;
7 | import org.springframework.cloud.client.discovery.DiscoveryClient;
8 | import org.springframework.web.bind.annotation.PathVariable;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RequestMethod;
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | import java.util.List;
14 |
15 | @RestController
16 | public class ServiceController {
17 |
18 | @Autowired
19 | private EurekaClient eurekaClient;
20 | @Autowired
21 | private DiscoveryClient discoveryClient;
22 |
23 | /**
24 | * 根据eureka实例名${spring.application.name}
25 | * @return
26 | */
27 | @RequestMapping(value = "/serviceUrl/1/{name}", method = RequestMethod.GET)
28 | public String serviceUrl1(@PathVariable("name") String name) {
29 | try {
30 | InstanceInfo instance = eurekaClient.getNextServerFromEureka(name, false);
31 | return instance.getHomePageUrl();
32 | }catch (RuntimeException ex){
33 | return ex.getMessage();
34 | }
35 | }
36 |
37 | /**
38 | * 根据eureka实例名${spring.application.name}
39 | * @return
40 | */
41 | @RequestMapping(value = "/serviceUrl/2/{name}", method = RequestMethod.GET)
42 | public String serviceUrl2(@PathVariable("name") String name) {
43 | List list = discoveryClient.getInstances(name);
44 | if (list != null && list.size() > 0 ) {
45 | return list.stream()
46 | .reduce("", (result, element) -> result +=
47 | element.getHost() + ":" + element.getPort() + "," + element.getServiceId() + "
",
48 | (u, t) -> t);
49 | }
50 |
51 | return "No matches for the virtual host name :" + name;
52 | }
53 |
54 |
55 |
56 | @RequestMapping("/hello")
57 | public String hello() {
58 | ServiceInstance localInstance = discoveryClient.getLocalServiceInstance();
59 | return "Hello World: "+ localInstance.getServiceId()+":"+localInstance.getHost()+":"+localInstance.getPort();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/model/Company.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Company {
7 | private Long id;
8 | private String name;
9 |
10 | public Company(Long id, String name) {
11 | this.id = id;
12 | this.name = name;
13 | }
14 |
15 | public Long getId() {
16 | return id;
17 | }
18 |
19 | public void setId(Long id) {
20 | this.id = id;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/model/OneCompany.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.model;
2 |
3 | import com.zzqfsy.cloud.eureka.service.rpc.model.Employee;
4 | import com.zzqfsy.cloud.eureka.service.rpc.model.Product;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by john on 16-10-28.
10 | */
11 | public class OneCompany {
12 | Company company;
13 | List employees;
14 | List products;
15 |
16 | public OneCompany() {
17 | }
18 |
19 | public OneCompany(
20 | Company company,
21 | List employees,
22 | List products
23 | ) {
24 | this.company = company;
25 | this.employees = employees;
26 | this.products = products;
27 | }
28 |
29 | public Company getCompany() {
30 | return company;
31 | }
32 |
33 | public void setCompany(Company company) {
34 | this.company = company;
35 | }
36 |
37 | public List getEmployees() {
38 | return employees;
39 | }
40 |
41 | public void setEmployees(List employees) {
42 | this.employees = employees;
43 | }
44 |
45 | public List getProducts() {
46 | return products;
47 | }
48 |
49 | public void setProducts(List products) {
50 | this.products = products;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/feign/EmployeeFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.feign;
2 |
3 | import com.zzqfsy.cloud.eureka.service.rpc.model.Employee;
4 | import org.springframework.cloud.netflix.feign.FeignClient;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by john on 16-10-28.
13 | */
14 | @FeignClient("eurekadashboard")
15 | public interface EmployeeFeignClient {
16 | @RequestMapping("/api/employees/{id}")
17 | Employee getEmployeeById(@PathVariable("id") Long id);
18 |
19 | @RequestMapping("/api/employees/")
20 | List getEmployeesByCompanyId(@RequestParam("companyId") Long companyId);
21 | }
22 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/feign/ProductFeignClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.feign;
2 |
3 | import com.zzqfsy.cloud.eureka.service.rpc.model.Product;
4 | import org.springframework.cloud.netflix.feign.FeignClient;
5 | import org.springframework.http.MediaType;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by john on 16-10-21.
15 | */
16 | @FeignClient("eureka-server")
17 | public interface ProductFeignClient {
18 | @RequestMapping(value = "/api/products/{id}", method = RequestMethod.GET)
19 | Product getProductById(@PathVariable("id") Long id);
20 |
21 | @RequestMapping(value = "/api/products/", method = RequestMethod.GET,
22 | produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
23 | List getProductsByCompanyId(@RequestParam("companyId") Long companyId);
24 | }
25 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/hytrix/EmployeeHystrixClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.zzqfsy.cloud.eureka.service.rpc.feign.EmployeeFeignClient;
5 | import com.zzqfsy.cloud.eureka.service.rpc.model.Employee;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by john on 16-10-28.
14 | */
15 | @Service("employeeHystrixClient")
16 | public class EmployeeHystrixClient {
17 | @Autowired
18 | EmployeeFeignClient employeeFeignClient;
19 |
20 | @HystrixCommand(groupKey = "eurekadashboard", fallbackMethod = "fallBackCall")
21 | public Employee getEmployeeById(Long companyId) {
22 | return employeeFeignClient.getEmployeeById(companyId);
23 | }
24 |
25 | @HystrixCommand(groupKey = "eurekadashboard", fallbackMethod = "fallBackCallList")
26 | public List getEmployeeByIds(Long companyId) {
27 | return employeeFeignClient.getEmployeesByCompanyId(companyId);
28 | }
29 |
30 |
31 | Employee fallBackCall(Long companyId){
32 | return new Employee(0L, 0L, "error");
33 | }
34 |
35 | List fallBackCallList(Long companyId){
36 | return Arrays.asList(new Employee(0L, 0L, "error"));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/hytrix/ProductHystrixClient.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.hytrix;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.zzqfsy.cloud.eureka.service.rpc.feign.ProductFeignClient;
5 | import com.zzqfsy.cloud.eureka.service.rpc.model.Product;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by john on 16-10-21.
14 | */
15 | @Service("productHystrixHelloClient")
16 | public class ProductHystrixClient {
17 | @Autowired
18 | private ProductFeignClient productFeignClient;
19 |
20 | @HystrixCommand(groupKey = "productGroup", fallbackMethod = "fallBackCall")
21 | public Product getProductById(Long id) {
22 | return productFeignClient.getProductById(id);
23 | }
24 |
25 | @HystrixCommand(groupKey = "productGroup2", fallbackMethod = "fallBackCallList")
26 | public List getProductsByCompanyId(Long companyId) {
27 | return productFeignClient.getProductsByCompanyId(companyId);
28 | }
29 |
30 | public Product fallBackCall(Long id) {
31 | return new Product(id, id, "FAILED SERVICE CALL! - FALLING BACK");
32 | }
33 |
34 | public List fallBackCallList(Long id) {
35 | return Arrays.asList(new Product(id, id, "FAILED SERVICE CALL! - FALLING BACK"));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/model/Employee.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Employee {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String name;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Employee() {
15 | }
16 |
17 | public Employee(Long id, Long companyId, String name) {
18 | this.id = id;
19 | this.companyId = companyId;
20 | this.name = name;
21 | }
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public Long getCompanyId() {
32 | return companyId;
33 | }
34 |
35 | public void setCompanyId(Long companyId) {
36 | this.companyId = companyId;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 | }
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/java/com/zzqfsy/cloud/eureka/service/rpc/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.eureka.service.rpc.model;
2 |
3 | /**
4 | * Created by john on 16-10-20.
5 | */
6 | public class Product {
7 |
8 | private Long id;
9 | private Long companyId;
10 | private String sku;
11 |
12 | // Constructor、Getter、Setter
13 |
14 | public Product() {
15 | }
16 |
17 | public Product(Long id, Long companyId, String sku) {
18 | this.id = id;
19 | this.companyId = companyId;
20 | this.sku = sku;
21 | }
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public Long getCompanyId() {
32 | return companyId;
33 | }
34 |
35 | public void setCompanyId(Long companyId) {
36 | this.companyId = companyId;
37 | }
38 |
39 | public String getSku() {
40 | return sku;
41 | }
42 |
43 | public void setSku(String sku) {
44 | this.sku = sku;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8062
3 |
4 | eureka:
5 | instance:
6 | appname: eurekaservice1
7 | leaseRenewalIntervalInSeconds: 10 #default 30 seconds
8 | metadataMap:
9 | instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
10 | #${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
11 | client:
12 | registerWithEureka: true
13 | fetchRegistry: true
14 | serviceUrl:
15 | defaultZone: http://127.0.0.1:8061/eureka/
16 |
17 | #http://eurekaserver10:8061/eureka/,http://eurekaserver20:8071/eureka/,http://eurekaserver30:8081/eureka/
18 |
19 | logging:
20 | levels:
21 | org.springframework.boot.env.PropertySourcesLoader: DEBUG
22 | org.springframework.web: DEBUG
23 | org.springframework.cloud: DEBUG
24 | level: DEBUG
25 |
26 | hystrix:
27 | command:
28 | default:
29 | execution:
30 | isolation:
31 | thread:
32 | timeoutInMilliseconds: 5000
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-cloud-eureka-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: eurekaservice1
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 | label: master
--------------------------------------------------------------------------------
/spring-cloud-zuul-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-cloud-zuul-server
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.zuul.ZuulApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-eureka
29 |
30 |
31 | org.springframework.cloud
32 | spring-cloud-starter-zuul
33 |
34 |
35 | org.springframework.cloud
36 | spring-cloud-starter-ribbon
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-actuator
41 |
42 |
43 |
--------------------------------------------------------------------------------
/spring-cloud-zuul-server/src/main/java/com/zzqfsy/cloud/zuul/ZuulApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.cloud.zuul;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
6 | import org.springframework.boot.builder.SpringApplicationBuilder;
7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
9 |
10 | /**
11 | * Created by john on 16-10-17.
12 | */
13 | @SpringBootApplication
14 | @EnableZuulProxy
15 | @EnableOAuth2Sso
16 | public class ZuulApplication {
17 |
18 | public static void main(String[] args) {
19 | new SpringApplicationBuilder(ZuulApplication.class).web(true).run(args);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-cloud-zuul-server/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8066
3 |
4 | endpoints:
5 | restart:
6 | enabled: true
7 | shutdown:
8 | enabled: true
9 | health:
10 | sensitive: false
11 |
12 | eureka:
13 | instance:
14 | appname: zuuledgeserver
15 | leaseRenewalIntervalInSeconds: 10 #default 30 seconds
16 | metadataMap:
17 | instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
18 | #${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
19 | client:
20 | registerWithEureka: true
21 | fetchRegistry: true
22 | serviceUrl:
23 | defaultZone: http://127.0.0.1:8061/eureka/
24 | #http://eurekaserver10:8061/eureka/,http://eurekaserver20:8071/eureka/,http://eurekaserver30:8081/eureka/
25 |
26 | zuul:
27 | #ignored-services: '*'
28 | #ignored-patterns: /**/admin/**
29 | prefix: /api
30 | stripPrefix: false
31 | routes:
32 | eurekaservice1:
33 | path: /companys/**
34 | serviceId: eurekaservice1
35 | stripPrefix: false
36 | eureka-server:
37 | path: /products/**
38 | #serviceId: eureka-server
39 | stripPrefix: false
40 | eurekadashboard:
41 | path: /employees/**
42 | serviceId: eurekadashboard
43 | stripPrefix: false
44 |
45 | ribbon:
46 | readTimeout: 5000
47 | hystrixTimeout: 4500
48 | execTime: 4000
49 |
50 | hystrix:
51 | command:
52 | default:
53 | execution:
54 | isolation:
55 | thread:
56 | timeoutInMilliseconds: 5000
57 |
58 | #ribbon:
59 | # restclient:
60 | # enabled: true
61 | # eureka:
62 | # enabled: false
63 |
64 | #companys:
65 | # ribbon:
66 | # listOfServers: example.com,google.com
67 |
--------------------------------------------------------------------------------
/spring-cloud-zuul-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-cloud-zuul-server/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: zuuledgeserver
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 | label: master
--------------------------------------------------------------------------------
/spring-security-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-cloud-demo
7 | com.zzqfsy.cloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-security-service
13 |
14 |
15 | 1.8
16 | com.zzqfsy.cloud.zuul.ZuulApplication
17 |
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-eureka
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-actuator
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-security
38 |
39 |
40 | org.springframework.security.oauth
41 | spring-security-oauth2
42 |
43 |
44 | org.springframework.security
45 | spring-security-jwt
46 |
47 |
48 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/java/com/zzqfsy/security/SecurityApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.security;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | /**
12 | * Created by john on 16-10-24.
13 | */
14 | @SpringBootApplication
15 | @EnableAuthorizationServer
16 | @EnableResourceServer
17 | @RestController
18 | public class SecurityApplication {
19 | public static void main(String[] args) {
20 | SpringApplication.run(SecurityApplication.class, args);
21 | }
22 |
23 | @RequestMapping("/user")
24 | @ResponseBody
25 | public String index() {
26 | return "index";
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/java/com/zzqfsy/security/config/OAuth2Config.java:
--------------------------------------------------------------------------------
1 | /*
2 | package com.zzqfsy.security.config;
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.core.io.ClassPathResource;
8 | import org.springframework.security.authentication.AuthenticationManager;
9 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
10 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
11 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
12 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
13 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
14 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
15 | import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
16 |
17 | import java.security.KeyPair;
18 |
19 | */
20 | /**
21 | * Created by john on 16-10-24.
22 | *//*
23 |
24 | @Configuration
25 | @EnableAuthorizationServer
26 | public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
27 |
28 | @Autowired
29 | private AuthenticationManager authenticationManager;
30 | @Override
31 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
32 | endpoints.authenticationManager(authenticationManager);
33 | }
34 | @Override
35 | public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
36 | oauthServer.checkTokenAccess("isAuthenticated()");
37 | }
38 | @Override
39 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
40 | clients.inMemory()
41 | .withClient("clientId")
42 | .secret("secretId")
43 | .authorizedGrantTypes("authorization_code", "client_credentials")
44 | .scopes("app");
45 | }
46 | }
47 | */
48 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/java/com/zzqfsy/security/config/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | package com.zzqfsy.security.config;
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.builders.WebSecurity;
9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11 | import org.springframework.security.config.http.SessionCreationPolicy;
12 |
13 | */
14 | /**
15 | * Created by john on 16-10-24.
16 | *//*
17 |
18 | @Configuration
19 | @EnableWebSecurity
20 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
21 |
22 | @Override
23 | protected void configure(HttpSecurity http) throws Exception {
24 | http.anonymous().disable()
25 | .sessionManagement()
26 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
27 | .and()
28 | .exceptionHandling()
29 | // .accessDeniedHandler(accessDeniedHandler()) // handle access denied in general (for example comming from @PreAuthorization
30 | // .authenticationEntryPoint(entryPointBean()) // handle authentication exceptions for unauthorized calls.
31 | .and()
32 | .authorizeRequests()
33 | // .antMatchers("/hystrix.stream*/
34 | /**", "/info", "/error").permitAll()
35 | .anyRequest().authenticated().and().csrf().disable();
36 | }
37 |
38 | // @Bean
39 | // @Autowired
40 | // AccessDeniedHandler accessDeniedHandler() {
41 | // return new AccessDeniedExceptionHandler();
42 | // }
43 | //
44 | // @Bean
45 | // @Autowired
46 | // AuthenticationEntryPoint entryPointBean() {
47 | // return new UnauthorizedEntryPoint();
48 | // }
49 | // 不需要权限控制的路径
50 | @Override
51 | public void configure(WebSecurity web) throws Exception {
52 | web.ignoring().antMatchers("/hystrix.stream*/
53 | /**", "/info", "/error");
54 | }
55 | }*/
56 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/java/com/zzqfsy/security/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.zzqfsy.security.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.ResponseBody;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | /**
9 | * Created by john on 16-10-24.
10 | */
11 | @RestController
12 | public class HelloController {
13 | @RequestMapping(value = "/hello", method = RequestMethod.GET)
14 | @ResponseBody
15 | public String hello() {
16 | return "hello";
17 | }
18 |
19 | @RequestMapping("/home")
20 | public String home() {
21 | return "home";
22 | }
23 |
24 | @RequestMapping("/logout")
25 | public String logout() {
26 | return "logout";
27 | }
28 |
29 | @RequestMapping("/login")
30 | public String login() {
31 | return "login";
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8069
3 | context-path: /api
4 |
5 | security:
6 | user:
7 | name: user
8 | password: password
9 | oauth2:
10 | client:
11 | client-id: acme
12 | client-secret: acmesecret
13 | authorized-grant-types: authorization_code,refresh_token,password
14 | scope: openid
15 | access-token-uri: http://localhost:8069/api/oauth/token
16 | user-authorization-uri: http://localhost:8069/api/oauth/authorize
17 |
18 | eureka:
19 | instance:
20 | appname: securityservice
21 | leaseRenewalIntervalInSeconds: 10 #default 30 seconds
22 | metadataMap:
23 | instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
24 | #${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
25 | client:
26 | registerWithEureka: true
27 | fetchRegistry: true
28 | serviceUrl:
29 | defaultZone: http://127.0.0.1:8061/eureka/
30 | #http://eurekaserver10:8061/eureka/,http://eurekaserver20:8071/eureka/,http://eurekaserver30:8081/eureka/
31 |
32 | logging:
33 | levels:
34 | org.springframework.boot.env.PropertySourcesLoader: DEBUG
35 | org.springframework.web: DEBUG
36 | org.springframework.cloud: DEBUG
37 | org.springframework.security: DEBUG
38 | level: DEBUG
39 |
--------------------------------------------------------------------------------
/spring-security-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: dev
--------------------------------------------------------------------------------
/spring-security-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: securityservice
4 | cloud:
5 | config:
6 | enabled: true
7 | uri: http://127.0.0.1:8060
8 | profile: dev
9 | label: master
--------------------------------------------------------------------------------
/spring-security-service/src/main/resources/keystore.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzqfsy/spring-cloud-demo/87ae06961f7b491c9c29ca101199f16cbda4bc59/spring-security-service/src/main/resources/keystore.jks
--------------------------------------------------------------------------------
/summery.graphml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | 用户
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 服务边界
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | Folder 2
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | 监控服务eurekadashboard
76 | (spring-cloud-eureka-dashboard)
77 | (EmployeeService)
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | 配置服务configserver
95 | (spring-cloud-config-service)
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | 发现注册集群
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | Folder 1
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | 注册发现服务eurekaserver20
163 | (spring-cloud-eureka-server)
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 | 注册发现服务eurekaserver10
181 | (spring-cloud-eureka-server)
182 | (ProductService)
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 | 注册发现服务eurekaserver30
200 | (spring-cloud-eureka-server)
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 | 业务边界
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 | Folder 3
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 | 网关服务
252 | (spring-cloud-zuul-server)
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 | 鉴权服务securityservice
270 | (spring-security-service)
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 | 业务服务eurekaservice1
288 | (spring-cloud-eureka-service)
289 | (CompanyService)
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 | 模拟终端
307 | 配置客户端configclient
308 | (spring-cloud-config-client)
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 | 业务服务eurekaclient1
326 | (spring-cloud-eureka-client)
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 | 终端
344 | (ios/android/h5)
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 | <?xml version="1.0" encoding="utf-8"?>
493 | <svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
494 | width="59px" height="59px" viewBox="0 0 59 59" enable-background="new 0 0 59 59" xml:space="preserve">
495 | <g>
496 |
497 | <linearGradient id="neck_x5F_white_1_" gradientUnits="userSpaceOnUse" x1="13.6323" y1="-1502.7422" x2="14.3617" y2="-1520.2559" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
498 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
499 | <stop offset="1" style="stop-color:#FFD28F"/>
500 | </linearGradient>
501 | <path id="neck_x5F_white_19_" fill="url(#neck_x5F_white_1_)" stroke="#FFAB4F" stroke-width="0.5" stroke-miterlimit="10" d="
502 | M9.639,18.899h9.093v10.115c-0.656,0.186-8.586,0.218-9.093,0.086V18.899z"/>
503 |
504 | <linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="13.1294" y1="-1499.207" x2="13.75" y2="-1514.1072" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
505 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
506 | <stop offset="1" style="stop-color:#FFD28F"/>
507 | </linearGradient>
508 | <path fill="url(#SVGID_1_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="M24.766,25.612
509 | c-2.199-2.197-5.477-2.941-6.033-3.055v-3.658H9.639c0,0,0.019,3.452,0,3.435c0,0-3.437,0.499-6.154,3.216
510 | c-2.796,2.796-3.235,5.835-3.235,5.835c0,0.971,0.788,1.746,1.762,1.746h24.255c0.974,0,1.761-0.777,1.761-1.746
511 | C28.027,31.384,27.105,27.953,24.766,25.612z"/>
512 |
513 | <radialGradient id="face_x5F_white_1_" cx="13.7515" cy="-1500.0908" r="11.7123" fx="11.4666" fy="-1501.3357" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
514 | <stop offset="0" style="stop-color:#FFD28F"/>
515 | <stop offset="1" style="stop-color:#FFAB4F"/>
516 | </radialGradient>
517 | <path id="face_x5F_white_19_" fill="url(#face_x5F_white_1_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="
518 | M21.838,11.679c0.043,5.1-3.369,9.26-7.623,9.293C9.964,21.006,6.483,16.899,6.44,11.8c-0.042-5.1,3.37-9.261,7.622-9.294
519 | C18.314,2.473,21.795,6.579,21.838,11.679z"/>
520 |
521 | <linearGradient id="face_highlight_1_" gradientUnits="userSpaceOnUse" x1="4300.0391" y1="8522.0703" x2="4311.8545" y2="8568.7988" gradientTransform="matrix(0.275 0 0 0.2733 -1169.7629 -2324.9595)">
522 | <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.24"/>
523 | <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.16"/>
524 | </linearGradient>
525 | <path id="face_highlight_19_" fill="url(#face_highlight_1_)" d="M13.979,3.166c-3.018,0.023-5.374,2.247-6.394,5.193
526 | c-0.332,0.96-0.147,2.021,0.49,2.814c1.365,1.699,2.865,3.142,4.73,4.044c1.569,0.759,3.767,1.192,5.946,0.624
527 | c1.139-0.297,1.994-1.229,2.188-2.383c0.092-0.548,0.146-1.145,0.143-1.777C21.041,6.977,18.137,3.134,13.979,3.166z"/>
528 |
529 | <path id="Hair_Female_1_Black_9_" fill="#4B4B4B" stroke="#000000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="
530 | M14.187,0.25c-5.418,0-10.052,3.624-9.61,12.813c0.282,3.281,2.931,6.021,4.683,6.766C7.795,14.344,9.107,7.317,8.967,7.064
531 | c-0.14-0.252,1.769,3.364,1.769,3.364l1.591-4.155c2.771,2.14,0.197,5.654,0.524,5.528c2.129-0.815,2.67-4.614,2.67-4.614
532 | s1.364,1.829,1.35,2.752c-0.025,1.781,1.098-3.033,1.098-3.033l0.514,1.016c3.363,4.911,1.842,8.104,0.826,11.391
533 | c7.834-0.352,6.146-5.24,4.83-9.203C21.795,3.046,19.604,0.25,14.187,0.25z"/>
534 |
535 | <linearGradient id="body_1_" gradientUnits="userSpaceOnUse" x1="53.4854" y1="2393.7295" x2="21.2897" y2="2393.7295" gradientTransform="matrix(0.9852 0 0 0.9852 -22.6981 -2330.2188)">
536 | <stop offset="0" style="stop-color:#49AD33"/>
537 | <stop offset="1" style="stop-color:#C2DA92"/>
538 | </linearGradient>
539 | <path id="body_63_" fill="url(#body_1_)" stroke="#008D33" stroke-width="0.5" d="M0.25,31.384c0,0.97,0.788,1.747,1.762,1.747
540 | h24.255c0.974,0,1.761-0.779,1.761-1.747c0,0-0.922-3.431-3.262-5.771c-2.408-2.406-4.123-2.572-4.123-2.572
541 | c-0.723,3.491-4.277,4.393-6.503,4.393c-2.227,0-5.75-0.994-6.06-4.393c0,0-1.877-0.207-4.594,2.51
542 | C0.689,28.345,0.25,31.384,0.25,31.384z"/>
543 |
544 | <linearGradient id="neck_x5F_white_3_" gradientUnits="userSpaceOnUse" x1="43.8525" y1="-1502.7417" x2="44.5819" y2="-1520.2552" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
545 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
546 | <stop offset="1" style="stop-color:#FFD28F"/>
547 | </linearGradient>
548 | <path id="neck_x5F_white_17_" fill="url(#neck_x5F_white_3_)" stroke="#FFAB4F" stroke-width="0.5" stroke-miterlimit="10" d="
549 | M39.859,18.899h9.094v10.115c-0.656,0.186-8.586,0.218-9.094,0.086V18.899z"/>
550 |
551 | <linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="43.3506" y1="-1499.2075" x2="43.9712" y2="-1514.1077" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
552 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
553 | <stop offset="1" style="stop-color:#FFD28F"/>
554 | </linearGradient>
555 | <path fill="url(#SVGID_2_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="M54.986,25.612
556 | c-2.199-2.197-5.478-2.941-6.033-3.055v-3.658h-9.094c0,0,0.02,3.452,0,3.435c0,0-3.438,0.499-6.153,3.216
557 | c-2.796,2.796-3.235,5.835-3.235,5.835c0,0.971,0.787,1.746,1.762,1.746h24.256c0.974,0,1.761-0.777,1.761-1.746
558 | C58.248,31.384,57.326,27.953,54.986,25.612z"/>
559 |
560 | <radialGradient id="face_x5F_white_3_" cx="43.9727" cy="-1500.0908" r="11.7111" fx="41.6881" fy="-1501.3356" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
561 | <stop offset="0" style="stop-color:#FFD28F"/>
562 | <stop offset="1" style="stop-color:#FFAB4F"/>
563 | </radialGradient>
564 | <path id="face_x5F_white_17_" fill="url(#face_x5F_white_3_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="
565 | M52.059,11.679c0.043,5.1-3.369,9.26-7.623,9.293c-4.25,0.034-7.731-4.073-7.774-9.172c-0.042-5.1,3.368-9.261,7.622-9.294
566 | C48.536,2.473,52.016,6.579,52.059,11.679z"/>
567 |
568 | <linearGradient id="face_highlight_3_" gradientUnits="userSpaceOnUse" x1="4409.9326" y1="8522.0703" x2="4421.7476" y2="8568.7969" gradientTransform="matrix(0.275 0 0 0.2733 -1169.7629 -2324.9595)">
569 | <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.24"/>
570 | <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.16"/>
571 | </linearGradient>
572 | <path id="face_highlight_17_" fill="url(#face_highlight_3_)" d="M44.2,3.166c-3.019,0.023-5.374,2.247-6.394,5.193
573 | c-0.332,0.96-0.147,2.021,0.489,2.814c1.364,1.699,2.864,3.142,4.729,4.044c1.568,0.759,3.768,1.192,5.945,0.624
574 | c1.139-0.297,1.994-1.229,2.188-2.383c0.092-0.548,0.146-1.145,0.143-1.777C51.262,6.977,48.357,3.134,44.2,3.166z"/>
575 |
576 | <path id="hair_x5F_gray_17_" fill="#ECECEC" stroke="#9B9B9B" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="
577 | M40.359,6.625c0,0,2.66,3.625,7.5,1.875c1.365-0.281,4.529,0.518,4.529,0.518s-1.828-8.085-8.523-7.646
578 | c-8.943,0.69-7.615,11.467-7.615,11.467s1.384-0.342,2.518-2.401C39.255,9.553,40.359,6.625,40.359,6.625z"/>
579 |
580 | <radialGradient id="collar_x5F_body_2_" cx="37.6602" cy="-1515.813" r="16.2003" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
581 | <stop offset="0" style="stop-color:#B0E8FF"/>
582 | <stop offset="1" style="stop-color:#74AEEE"/>
583 | </radialGradient>
584 | <path id="collar_x5F_body_8_" fill="url(#collar_x5F_body_2_)" stroke="#5491CF" stroke-width="0.5" d="M30.471,31.384
585 | c0,0.97,0.787,1.747,1.762,1.747h24.256c0.974,0,1.761-0.779,1.761-1.747c0,0-0.922-3.431-3.263-5.771
586 | c-2.407-2.406-5.623-3.072-5.623-3.072c-0.885,0.827-2.805,1.4-5.03,1.4s-4.146-0.573-5.031-1.4c0,0-2.878,0.293-5.595,3.01
587 | C30.91,28.345,30.471,31.384,30.471,31.384z"/>
588 |
589 | <radialGradient id="collar_x5F_r_2_" cx="45.8311" cy="-1510.8745" r="4.6401" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
590 | <stop offset="0" style="stop-color:#80CCFF"/>
591 | <stop offset="1" style="stop-color:#74AEEE"/>
592 | </radialGradient>
593 | <path id="collar_x5F_r_8_" fill="url(#collar_x5F_r_2_)" stroke="#5491CF" stroke-width="0.5" d="M49.301,20.69
594 | c0,0-0.287,1.185-1.506,2.221c-1.055,0.897-2.893,1.036-2.893,1.036l1.986,3.108c0,0,1.479-0.818,2.504-1.924
595 | c0.961-1.036,0.686-2.74,0.686-2.74L49.301,20.69z"/>
596 |
597 | <radialGradient id="collar_x5F_l_2_" cx="39.6494" cy="-1510.896" r="4.6426" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
598 | <stop offset="0" style="stop-color:#80CCFF"/>
599 | <stop offset="1" style="stop-color:#74AEEE"/>
600 | </radialGradient>
601 | <path id="collar_x5F_l_8_" fill="url(#collar_x5F_l_2_)" stroke="#5491CF" stroke-width="0.5" d="M39.536,20.711
602 | c0,0,0.288,1.185,1.506,2.221c1.056,0.896,2.894,1.036,2.894,1.036l-1.987,3.108c0,0-1.479-0.818-2.505-1.925
603 | c-0.961-1.036-0.685-2.74-0.685-2.74L39.536,20.711z"/>
604 |
605 | <radialGradient id="Knob2_2_" cx="44.0645" cy="-742.6421" r="0.4846" gradientTransform="matrix(1 0 0 -1 0.1201 -714.5371)" gradientUnits="userSpaceOnUse">
606 | <stop offset="0" style="stop-color:#80CCFF"/>
607 | <stop offset="1" style="stop-color:#74AEEE"/>
608 | </radialGradient>
609 | <circle id="Knob2_8_" fill="url(#Knob2_2_)" stroke="#5491CF" stroke-width="0.5" cx="44.35" cy="28.127" r="0.292"/>
610 |
611 | <radialGradient id="Knob1_2_" cx="44.083" cy="-745.7642" r="0.4847" gradientTransform="matrix(1 0 0 -1 0.1201 -714.5371)" gradientUnits="userSpaceOnUse">
612 | <stop offset="0" style="stop-color:#80CCFF"/>
613 | <stop offset="1" style="stop-color:#74AEEE"/>
614 | </radialGradient>
615 | <circle id="Knob1_8_" fill="url(#Knob1_2_)" stroke="#5491CF" stroke-width="0.5" cx="44.369" cy="31.25" r="0.292"/>
616 |
617 | <radialGradient id="jacket_x5F_body_1_" cx="36.7842" cy="-1515.3755" r="20.459" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
618 | <stop offset="0" style="stop-color:#D0D0D0"/>
619 | <stop offset="1" style="stop-color:#9B9B9B"/>
620 | </radialGradient>
621 |
622 | <path id="jacket_x5F_body_8_" fill="url(#jacket_x5F_body_1_)" stroke="#4B4B4B" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="
623 | M54.986,25.612c-2.217-2.217-5.111-2.955-5.557-3.059l-2.695,10.572h-4.43L39.686,22.84c-0.145-0.096-0.271-0.196-0.385-0.301
624 | c0,0-2.877,0.293-5.595,3.01c-2.796,2.796-3.233,5.835-3.233,5.835c0,0.97,0.786,1.747,1.76,1.747h24.256
625 | c0.975,0,1.761-0.779,1.761-1.747C58.248,31.384,57.326,27.953,54.986,25.612z"/>
626 |
627 | <polygon id="jacket_x5F_r_8_" fill="#9B9B9B" stroke="#4B4B4B" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" points="
628 | 49.688,21.038 51.305,23.187 50.615,27.835 48.914,28.25 49.547,29.563 47.509,33.126 46.734,33.126 "/>
629 |
630 | <polygon id="jacket_x5F_l_8_" fill="#B2B2B2" stroke="#4B4B4B" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" points="
631 | 39.354,21.038 37.734,23.187 38.426,27.835 40.127,28.25 39.493,29.563 41.531,33.126 42.307,33.126 "/>
632 | <path id="path5135_8_" fill="#D54A30" stroke="#B51A19" stroke-width="0.5" d="M43.936,27.61c0,0-0.926,1.028-1.041,3.271
633 | c-0.115,2.244,0,2.244,0,2.244h3.273c0,0,0.115,0.031-0.077-2.182c-0.2-2.302-1.194-3.334-1.194-3.334L43.936,27.61L43.936,27.61z"
634 | />
635 | <path id="path5131_8_" fill="#D54A30" stroke="#B51A19" stroke-width="0.5" d="M44.377,24.34h0.063l1.275,2.001
636 | c0.258,0.477-0.604,0.898-0.729,1.274l-1.139-0.008c-0.121-0.38-1.129-0.683-0.738-1.292L44.377,24.34z"/>
637 |
638 | <linearGradient id="neck_x5F_white_4_" gradientUnits="userSpaceOnUse" x1="43.6328" y1="-1527.7417" x2="44.3621" y2="-1545.2545" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
639 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
640 | <stop offset="1" style="stop-color:#FFD28F"/>
641 | </linearGradient>
642 | <path id="neck_x5F_white_11_" fill="url(#neck_x5F_white_4_)" stroke="#FFAB4F" stroke-width="0.5" stroke-miterlimit="10" d="
643 | M39.639,43.898h9.094v10.115c-0.655,0.187-8.586,0.219-9.094,0.086V43.898z"/>
644 |
645 | <linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="43.1309" y1="-1524.2065" x2="43.7515" y2="-1539.1072" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)">
646 | <stop offset="0.2711" style="stop-color:#FFAB4F"/>
647 | <stop offset="1" style="stop-color:#FFD28F"/>
648 | </linearGradient>
649 | <path fill="url(#SVGID_3_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="M54.766,50.611
650 | c-2.199-2.196-5.477-2.94-6.033-3.055v-3.658h-9.094c0,0,0.021,3.453,0,3.436c0,0-3.437,0.499-6.152,3.216
651 | c-2.797,2.796-3.235,5.835-3.235,5.835c0,0.971,0.787,1.746,1.763,1.746h24.254c0.975,0,1.762-0.777,1.762-1.746
652 | C58.027,56.384,57.105,52.953,54.766,50.611z"/>
653 |
654 | <radialGradient id="face_x5F_white_4_" cx="43.752" cy="-1525.0908" r="11.7114" fx="41.4673" fy="-1526.3356" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
655 | <stop offset="0" style="stop-color:#FFD28F"/>
656 | <stop offset="1" style="stop-color:#FFAB4F"/>
657 | </radialGradient>
658 | <path id="face_x5F_white_11_" fill="url(#face_x5F_white_4_)" stroke="#ED9135" stroke-width="0.5" stroke-miterlimit="10" d="
659 | M51.838,36.68c0.043,5.1-3.369,9.26-7.623,9.293c-4.251,0.033-7.732-4.074-7.775-9.173c-0.041-5.1,3.369-9.261,7.623-9.294
660 | C48.314,27.473,51.795,31.579,51.838,36.68z"/>
661 |
662 | <linearGradient id="face_highlight_4_" gradientUnits="userSpaceOnUse" x1="4409.1299" y1="8613.5469" x2="4420.9448" y2="8660.2725" gradientTransform="matrix(0.275 0 0 0.2733 -1169.7629 -2324.9595)">
663 | <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.24"/>
664 | <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.16"/>
665 | </linearGradient>
666 | <path id="face_highlight_11_" fill="url(#face_highlight_4_)" d="M43.979,28.166c-3.018,0.023-5.373,2.247-6.394,5.193
667 | c-0.332,0.959-0.147,2.021,0.49,2.813c1.364,1.699,2.864,3.142,4.729,4.044c1.568,0.76,3.768,1.192,5.945,0.624
668 | c1.139-0.297,1.994-1.229,2.188-2.383c0.092-0.548,0.146-1.146,0.144-1.776C51.041,31.977,48.137,28.134,43.979,28.166z"/>
669 | <path fill="#CC9869" stroke="#99724F" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="M46.107,29.969
670 | c0,0,2.845,1.375,3.845,4.062c1.052,2.826,2.062,4.117,2.095,4c0.938-3.395,0.531-10.718-5.086-10.792
671 | c-10.229-3.832-12.79,5.98-11.947,9.824c0.539,2.457,1.117,3.344,1.971,4.041C36.982,41.104,37.514,33.781,46.107,29.969z"/>
672 |
673 | <linearGradient id="body_2_" gradientUnits="userSpaceOnUse" x1="83.9365" y1="2419.1064" x2="51.7404" y2="2419.1064" gradientTransform="matrix(0.9852 0 0 0.9852 -22.6981 -2330.2188)">
674 | <stop offset="0" style="stop-color:#49AD33"/>
675 | <stop offset="1" style="stop-color:#C2DA92"/>
676 | </linearGradient>
677 | <path id="body_35_" fill="url(#body_2_)" stroke="#008D33" stroke-width="0.5" d="M30.25,56.384c0,0.97,0.787,1.747,1.762,1.747
678 | h24.256c0.974,0,1.76-0.779,1.76-1.747c0,0-0.922-3.431-3.262-5.771c-2.408-2.406-4.123-2.572-4.123-2.572
679 | c-0.723,3.49-4.276,4.393-6.504,4.393c-2.227,0-5.75-0.994-6.059-4.393c0,0-1.878-0.207-4.596,2.51
680 | C30.689,53.346,30.25,56.384,30.25,56.384z"/>
681 |
682 | <radialGradient id="neck_x5F_white_5_" cx="14.0952" cy="-1534.9302" r="5.7236" fx="12.9786" fy="-1535.5386" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
683 | <stop offset="0" style="stop-color:#B38E5D"/>
684 | <stop offset="1" style="stop-color:#805126"/>
685 | </radialGradient>
686 | <path id="neck_x5F_white_2_" fill="url(#neck_x5F_white_5_)" stroke="#5B453B" stroke-width="0.5" stroke-miterlimit="10" d="
687 | M9.859,43.898h9.094v6.615c-0.656,0.187-8.586,0.219-9.094,0.086V43.898z"/>
688 |
689 | <radialGradient id="SVGID_4_" cx="13.8213" cy="-1539.1084" r="15.5272" fx="10.7923" fy="-1540.7589" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
690 | <stop offset="0" style="stop-color:#B38E5D"/>
691 | <stop offset="1" style="stop-color:#805126"/>
692 | </radialGradient>
693 | <path fill="url(#SVGID_4_)" stroke="#5B453B" stroke-width="0.5" stroke-miterlimit="10" d="M24.986,50.611
694 | c-2.199-2.196-5.477-2.94-6.033-3.055v-3.658H9.859c0,0,0.02,3.453,0,3.436c0,0-3.437,0.499-6.153,3.216
695 | c-2.796,2.796-3.235,5.835-3.235,5.835c0,0.971,0.787,1.746,1.762,1.746h24.255c0.974,0,1.761-0.777,1.761-1.746
696 | C28.248,56.384,27.326,52.953,24.986,50.611z"/>
697 |
698 | <radialGradient id="face_x5F_white_5_" cx="13.9722" cy="-1525.0908" r="11.7123" fx="11.6873" fy="-1526.3357" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
699 | <stop offset="0" style="stop-color:#B38E5D"/>
700 | <stop offset="1" style="stop-color:#805126"/>
701 | </radialGradient>
702 | <path id="face_x5F_white_2_" fill="url(#face_x5F_white_5_)" stroke="#5B453B" stroke-width="0.5" stroke-miterlimit="10" d="
703 | M22.059,36.68c0.043,5.1-3.369,9.26-7.623,9.293c-4.251,0.033-7.732-4.074-7.775-9.173c-0.042-5.1,3.369-9.261,7.622-9.294
704 | C18.536,27.473,22.016,31.579,22.059,36.68z"/>
705 |
706 | <linearGradient id="face_highlight_5_" gradientUnits="userSpaceOnUse" x1="4300.8428" y1="8613.5449" x2="4312.6582" y2="8660.2734" gradientTransform="matrix(0.275 0 0 0.2733 -1169.7629 -2324.9595)">
707 | <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.42"/>
708 | <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.12"/>
709 | </linearGradient>
710 | <path id="face_highlight_2_" fill="url(#face_highlight_5_)" d="M14.2,28.166c-3.018,0.023-5.374,2.247-6.394,5.193
711 | c-0.332,0.959-0.147,2.021,0.49,2.813c1.364,1.699,2.864,3.142,4.73,4.044c1.568,0.76,3.767,1.192,5.945,0.624
712 | c1.139-0.297,1.994-1.229,2.188-2.383c0.092-0.548,0.146-1.146,0.143-1.776C21.262,31.977,18.357,28.134,14.2,28.166z"/>
713 |
714 | <path id="Hair_Young_Black_1_" fill="#4B4B4B" stroke="#000000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="
715 | M10.359,31.625c1.709,2.166,4.667,3.459,4.667,3.459l-0.708-1.75c0,0,3.547,2.346,4.041,2.166c0.484-0.1-0.541-1.902-0.541-1.902
716 | s1.568,0.896,2.428,1.983c0.9,1.14,2.143,1.752,2.143,1.752s1.346-10.974-8.523-10.961C4.359,26.354,6.25,38.839,6.25,38.839
717 | L7.568,33.5c0,0,0.457,2.879,0.699,2.438C9.151,32.605,9.651,30.75,10.359,31.625z"/>
718 |
719 | <radialGradient id="collar_x5F_body_3_" cx="7.6602" cy="-1540.813" r="16.2003" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
720 | <stop offset="0" style="stop-color:#B0E8FF"/>
721 | <stop offset="1" style="stop-color:#74AEEE"/>
722 | </radialGradient>
723 | <path id="collar_x5F_body_1_" fill="url(#collar_x5F_body_3_)" stroke="#5491CF" stroke-width="0.5" d="M0.471,56.384
724 | c0,0.97,0.787,1.747,1.762,1.747h24.255c0.974,0,1.761-0.779,1.761-1.747c0,0-0.922-3.431-3.262-5.771
725 | c-2.408-2.406-5.623-3.072-5.623-3.072c-0.885,0.827-2.805,1.4-5.031,1.4s-4.146-0.573-5.031-1.4c0,0-2.878,0.293-5.595,3.01
726 | C0.91,53.346,0.471,56.384,0.471,56.384z"/>
727 |
728 | <radialGradient id="collar_x5F_r_3_" cx="15.8306" cy="-1535.874" r="4.6412" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
729 | <stop offset="0" style="stop-color:#80CCFF"/>
730 | <stop offset="1" style="stop-color:#74AEEE"/>
731 | </radialGradient>
732 | <path id="collar_x5F_r_1_" fill="url(#collar_x5F_r_3_)" stroke="#5491CF" stroke-width="0.5" d="M19.301,45.689
733 | c0,0-0.287,1.186-1.506,2.222c-1.055,0.897-2.893,1.036-2.893,1.036l1.986,3.107c0,0,1.479-0.818,2.504-1.924
734 | c0.961-1.035,0.686-2.74,0.686-2.74L19.301,45.689z"/>
735 |
736 | <radialGradient id="collar_x5F_l_3_" cx="9.6494" cy="-1535.896" r="4.6422" gradientTransform="matrix(1 0 0 -1 0.2002 -1487.2285)" gradientUnits="userSpaceOnUse">
737 | <stop offset="0" style="stop-color:#80CCFF"/>
738 | <stop offset="1" style="stop-color:#74AEEE"/>
739 | </radialGradient>
740 | <path id="collar_x5F_l_1_" fill="url(#collar_x5F_l_3_)" stroke="#5491CF" stroke-width="0.5" d="M9.536,45.711
741 | c0,0,0.288,1.186,1.506,2.221c1.055,0.896,2.893,1.037,2.893,1.037l-1.987,3.107c0,0-1.479-0.818-2.504-1.926
742 | c-0.961-1.035-0.685-2.739-0.685-2.739L9.536,45.711z"/>
743 |
744 | <radialGradient id="Knob2_3_" cx="14.0645" cy="-767.6421" r="0.4842" gradientTransform="matrix(1 0 0 -1 0.1201 -714.5371)" gradientUnits="userSpaceOnUse">
745 | <stop offset="0" style="stop-color:#80CCFF"/>
746 | <stop offset="1" style="stop-color:#74AEEE"/>
747 | </radialGradient>
748 | <circle id="Knob2_1_" fill="url(#Knob2_3_)" stroke="#5491CF" stroke-width="0.5" cx="14.35" cy="53.127" r="0.292"/>
749 |
750 | <radialGradient id="Knob1_3_" cx="14.0835" cy="-770.7642" r="0.4844" gradientTransform="matrix(1 0 0 -1 0.1201 -714.5371)" gradientUnits="userSpaceOnUse">
751 | <stop offset="0" style="stop-color:#80CCFF"/>
752 | <stop offset="1" style="stop-color:#74AEEE"/>
753 | </radialGradient>
754 | <circle id="Knob1_1_" fill="url(#Knob1_3_)" stroke="#5491CF" stroke-width="0.5" cx="14.369" cy="56.25" r="0.292"/>
755 | <path id="path5135_1_" fill="#D54A30" stroke="#B51A19" stroke-width="0.5" d="M13.935,52.609c0,0-0.925,1.029-1.04,3.271
756 | c-0.115,2.244,0,2.244,0,2.244h3.273c0,0,0.115,0.031-0.077-2.182c-0.2-2.303-1.194-3.334-1.194-3.334H13.935L13.935,52.609z"/>
757 | <path id="path5131_1_" fill="#D54A30" stroke="#B51A19" stroke-width="0.5" d="M14.377,49.34h0.062l1.276,2.001
758 | c0.258,0.478-0.604,0.897-0.728,1.274l-1.14-0.008c-0.121-0.381-1.128-0.684-0.738-1.293L14.377,49.34z"/>
759 | </g>
760 | </svg>
761 |
762 |
763 |
764 |
765 |
--------------------------------------------------------------------------------
/summery.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zzqfsy/spring-cloud-demo/87ae06961f7b491c9c29ca101199f16cbda4bc59/summery.jpg
--------------------------------------------------------------------------------