├── .gitignore ├── README.MD ├── j360-cloud-anothersimpleclient ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── anothersimpleclient │ │ └── Application.java │ └── resources │ ├── application.properties │ └── bootstrap.properties ├── j360-cloud-bus └── pom.xml ├── j360-cloud-client ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── client │ │ ├── Application.java │ │ ├── ConfigurationPropertiesConfig.java │ │ └── MessageController.java │ └── resources │ ├── application.properties │ └── bootstrap.properties ├── j360-cloud-cluster ├── pom.xml └── src │ ├── main │ ├── java │ │ └── me │ │ │ └── j360 │ │ │ └── cloud │ │ │ └── cluster │ │ │ └── ConfigServerApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── me.j360.cloud.cluster │ ├── RedisIT.java │ └── ZookeeperTests.java ├── j360-cloud-configserver ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── configserver │ │ └── ConfigServerApplication.java │ └── resources │ ├── application.properties │ └── bootstrap.properties ├── j360-cloud-eurekaclient ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── eurekaclient │ │ ├── EurekaClientApplication.java │ │ ├── controller │ │ └── HelloController.java │ │ ├── feign │ │ └── HelloClient.java │ │ └── hytrix │ │ └── HystrixWrappedHelloClient.java │ └── resources │ └── application.yml ├── j360-cloud-eurekadashboard ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── eurekadashboard │ │ └── DashboardApplication.java │ └── resources │ └── application.yml ├── j360-cloud-eurekaserver ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── eurekaserver │ │ └── EurekaApplication.java │ └── resources │ └── application.yml ├── j360-cloud-eurekaservice ├── pom.xml └── src │ └── main │ ├── java │ └── me │ │ └── j360 │ │ └── cloud │ │ └── erurekaservice │ │ ├── ServiceApplication.java │ │ └── controller │ │ └── ServiceController.java │ └── resources │ └── application.yml ├── j360-cloud-zookeeperclient ├── pom.xml └── src │ ├── main │ ├── java │ │ └── me │ │ │ └── j360 │ │ │ └── cloud │ │ │ └── zookeeperclient │ │ │ └── ZookeeperApplication.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── me │ └── j360 │ └── cloud │ └── zookeeperclient │ └── SampleApplicationTests.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .ant_targets 3 | .DS_Store 4 | .bpmn 5 | *.iml 6 | .idea 7 | rebel.xml 8 | .settings 9 | /target 10 | *.log 11 | *.development.properties 12 | *.dev.properties -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | j360-cloud-all 2 | ============== 3 | 4 | 基于spring cloud应用在分布式系统中的运用 5 | 6 | ##配置文件上下文## 7 | - bootstrap.yml 8 | - application.yml 9 | - 【注】建议采用bootstrap+application组合形式,一般bootstrap配置工程不可变参数,且在启动时需要设定的内容,application配置可变参数 10 | 11 | 12 | ##spring-cloud-configserver## 13 | =================== 14 | - configserver提供了HTTP,为外部资源提供API配置的服务,只需要在Springboot程序中提供@EnableConfigServer注解即可。 15 | - @EnableConfigServer 16 | - 增加以下依赖 eureka(可选,作为discover服务器必选) 17 | ``` 18 | 19 | org.springframework.cloud 20 | spring-cloud-config-server 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka 25 | 26 | ``` 27 | - 运行configserver,通过端点可以查看configserver的属性内容 28 | - http://localhost:8888/configserver/application.properties 29 | 30 | - 【注】本地文件系统仅仅用于测试环境,在生产环境请使用远程的git服务提供配置资源 31 | ##Environment Repository 环境变量仓库## 32 | =================== 33 | - https://github.com/xuminwlt/config-repo 34 | 35 | ###环境变量仓库使用3个变量:### 36 | - 查看/env可以看到下面三个属性 37 | - {application} 在客户端映射到"spring.application.name" 38 | - {profile} 在客户端映射到"spring.active.profiles",使用逗号分隔 39 | - {label}这是一个服务器端功能标签“版本”的一组配置文件 40 | 41 | 42 | - 默认的环境变量库使用git服务,也可以使用文件系统的服务 43 | - Config Server支持一个或者多个git仓库 44 | ``` 45 | spring: 46 | cloud: 47 | config: 48 | server: 49 | git: 50 | uri: https://github.com/spring-cloud-samples/config-repo 51 | repos: 52 | simple: https://github.com/simple/config-repo 53 | special: 54 | pattern: pattern*,*pattern1* 55 | uri: https://github.com/special/config-repo 56 | local: 57 | pattern: local* 58 | uri: file:/home/configsvc/config-repo 59 | ``` 60 | 61 | - Every repository can also optionally store config files in sub-directories, and patterns to search for those directories can be specified as searchPaths. 62 | 63 | ``` 64 | spring: 65 | cloud: 66 | config: 67 | server: 68 | git: 69 | uri: https://github.com/spring-cloud-samples/config-repo 70 | searchPaths: foo,bar* 71 | ``` 72 | 73 | - To use HTTP basic authentication on the remote repository add the "username" and "password" properties separately (not in the URL), e.g 74 | 75 | ``` 76 | spring: 77 | cloud: 78 | config: 79 | server: 80 | git: 81 | uri: https://github.com/spring-cloud-samples/config-repo 82 | username: trolley 83 | password: strongpassword 84 | ``` 85 | 86 | - 文件系统后端 87 | - 使用 spring.profiles.active=native 88 | 89 | - 嵌入式ConfigServer 90 | - 官方建议独立部署 91 | 92 | ##spring-cloud-client## 93 | - 使用以下依赖 94 | 95 | ``` 96 | 97 | org.springframework.cloud 98 | spring-cloud-starter-config 99 | 100 | ``` 101 | 102 | - 配置优先启动 103 | - 默认的springcloud应用程序启动行为,所有的客户端应用程序想要使用配置服务器的配置,需要: 104 | - bootstrap.yml(或一个环境变量)的服务器地址 105 | - spring.cloud.config.uri(默认为 “http://localhost:8888”)。 106 | 107 | - Eureka优先启动 108 | - 如果使用的是Spring CloudNetflix 和eureka service discovery,可以使用配置服务器注册Eureka 109 | 110 | - 环境变量刷新 111 | - post -> localhost:8080/refresh 112 | - 定时 113 | - 手动 114 | 115 | ``` 116 | The Config Server itself is stateless, so you can spin up as many as these as you need and find them via eureka. Underneath the server itself, the git implementation you point to needs to be highly available as well. So if you point to github (private or public), then git is as available as github is. If the config server can't reach git it will continue to serve what it has checked out even if it is stale. 117 | As far as gradual config changes, you could use a different branch and configure the canary to use that branch via spring.cloud.config.label and them merge the branch. You could also use profiles (eg application-.properties) and configure the canary to use the specified profile. 118 | I think the branch makes a little more sense, because you wouldn't have to reconfigure the non-canary nodes to use the new profile each time, just configure canary to use the branch. 119 | Either way, the only time apps see config chages (when using spring cloud config client) is on startup or when you POST to /refresh on each node. You can also POST to /bus/refresh?destination= if you use the Spring Cloud Bus to refresh all instances of a service at once. 120 | ``` 121 | 122 | - 基于spring cloud应用在分布式系统中的运用 123 | - config 124 | - eureka 125 | - monitor 126 | - servicediscover 127 | 128 | ##Spring Cloud Netflix## 129 | - 应用程序+Netflix 组件构建大型分布式系统。包括 130 | - 服务发现(Eureka) 131 | - 断路器(Hystrix) 132 | - 智能路由(Zuul) 133 | - 客户端负载均衡(Ribbon) 134 | 135 | ###服务发现(Eureka)### 136 | - Eureka Client 137 | - 注册 138 | - @EnableEurekaClient 139 | - application.yml 140 | 141 | ``` 142 | eureka: 143 | client: 144 | serviceUrl: 145 | defaultZone: http://localhost:8761/eureka/ 146 | ``` 147 | 148 | - Eureka Server 149 | - @EnableEurekaServer 150 | - 【注】服务器有一个主页界面,HTTP API Eureka功能端点 /eureka/ 151 | ####Standalone Mode#### 152 | - application.yml (Standalone Eureka Server) 153 | - serviceUrl指向同一个本地实例的host 154 | 155 | ``` 156 | server: 157 | port: 8761 158 | eureka: 159 | instance: 160 | hostname: localhost 161 | client: 162 | registerWithEureka: false 163 | fetchRegistry: false 164 | serviceUrl: 165 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 166 | ``` 167 | 168 | ####High Availability, Zones and Regions#### 169 | - ... 170 | 171 | ###断路器(Hystrix) ### 172 | - Hystrix Client 173 | - Hystrix DashBoard 174 | 175 | ###智能路由(Zuul) ### 176 | - Netflix uses Zuul for the following: 177 | - Authentication 178 | - Insights 179 | - Stress Testing 180 | - Canary Testing 181 | - Dynamic Routing 182 | - Service Migration 183 | - Load Shedding 184 | - Security 185 | - Static Response handling 186 | - Active/Active traffic management 187 | 188 | 189 | ###客户端负载均衡(Ribbon) ### 190 | - Ribbon提供客户端的负载均衡,可以为http和tcp客户端提供控制功能,Feign 同样使用Ribbon 191 | - 定制Ribbon客户端 192 | - Eureka中使用Ribbon 193 | 194 | ``` 195 | 196 | ``` 197 | - 直接使用RibbonAPI 198 | 199 | ``` 200 | public class MyClass { 201 | @Autowired 202 | private LoadBalancerClient loadBalancer; 203 | public void doStuff() { 204 | ServiceInstance instance = loadBalancer.choose("stores"); 205 | URI storesUri = URI.create(String.format("http://%s:%s", instance.getHost(), instance.getPort())); 206 | // ... do something with the URI 207 | } 208 | } 209 | ``` 210 | 211 | ##声明式 REST Client: Feign## 212 | - Spring Cloud整合Ribbon和Eureka提供负载均衡的http client时使用Feign. 213 | 214 | - 实例案例 215 | 216 | ``` 217 | @Configuration 218 | @ComponentScan 219 | @EnableAutoConfiguration 220 | @EnableEurekaClient 221 | @EnableFeignClients 222 | public class Application { 223 | public static void main(String[] args) { 224 | SpringApplication.run(Application.class, args); 225 | } 226 | } 227 | ``` 228 | - 调用(StoreClient.java) 229 | 230 | ``` 231 | @FeignClient("stores") 232 | public interface StoreClient { 233 | @RequestMapping(method = RequestMethod.GET, value = "/stores") 234 | List getStores(); 235 | @RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json") 236 | Store update(@PathParameter("storeId") Long storeId, Store store); 237 | } 238 | ``` 239 | 240 | ###继承支持### 241 | 242 | ``` 243 | UserService.java 244 | public interface UserService { 245 | @RequestMapping(method = RequestMethod.GET, value ="/users/{id}") 246 | User getUser(@PathVariable("id") long id); 247 | } 248 | UserResource.java 249 | @RestController 250 | public class UserResource implements UserService { 251 | } 252 | UserClient.java 253 | @FeignClient("users") 254 | public interface UserClient extends UserService { 255 | } 256 | ``` 257 | ##外部配置: Archaius## 258 | - netfilx客户端配置框架 259 | - push changes到客户端 260 | - poll 资源来更新资源 261 | - 通常不直接使用 262 | 263 | ##Spring Cloud Bus## 264 | - Spring Cloud Bus通过轻量级消息代理连接分布式系统的每个节点 265 | - 添加依赖spring-cloud-starter-bus-amqp 266 | - Rabbit config 267 | 268 | ``` 269 | spring: 270 | rabbitmq: 271 | host: mybroker.com 272 | port: 5672 273 | username: user 274 | password: secret 275 | ``` 276 | 277 | - http端点 278 | - /bus/* 279 | - /bus/env 发送key/values键值对更新spring环境变量 280 | - /bus/refresh 更新所有的环境变量 281 | 282 | ##Spring cloud Zookeeper## 283 | - zookeeper仅仅是作为数据存储的地方,同eureka一样,但是eureka简单很多,目前推荐eureka 284 | 285 | ##Spring cloud Cluster## 286 | - 分布式系统集成zookeeper、redis等,实现选举、分布式锁、一致性状态检查等等,目测该项目还未完成start自动配置 287 | - zookeeper 依赖 spring-cloud-cluster-zookeeper 288 | - redis 依赖 spring-cloud-cluster-redis -------------------------------------------------------------------------------- /j360-cloud-anothersimpleclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | j360-cloud-anothersimpleclient 8 | 1.0-SNAPSHOT 9 | 4.0.0 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-config 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-eureka 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | pl.project13.maven 50 | git-commit-id-plugin 51 | 52 | false 53 | 54 | 55 | 56 | 57 | maven-deploy-plugin 58 | 59 | true 60 | 61 | 62 | 63 | 64 | 65 | 66 | spring-snapshots 67 | Spring Snapshots 68 | http://repo.spring.io/libs-snapshot-local 69 | 70 | true 71 | 72 | 73 | 74 | spring-milestones 75 | Spring Milestones 76 | http://repo.spring.io/libs-milestone-local 77 | 78 | false 79 | 80 | 81 | 82 | spring-releases 83 | Spring Releases 84 | http://repo.spring.io/libs-release-local 85 | 86 | false 87 | 88 | 89 | 90 | 91 | 92 | spring-snapshots 93 | Spring Snapshots 94 | http://repo.spring.io/libs-snapshot-local 95 | 96 | true 97 | 98 | 99 | 100 | spring-milestones 101 | Spring Milestones 102 | http://repo.spring.io/libs-milestone-local 103 | 104 | false 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /j360-cloud-anothersimpleclient/src/main/java/me/j360/cloud/anothersimpleclient/Application.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.anothersimpleclient; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created with j360-cloud-all -> me.j360.cloud.client. 8 | * User: min_xu 9 | * Date: 2015/9/30 10 | * Time: 11:03 11 | * 说明: 12 | */ 13 | 14 | @SpringBootApplication 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /j360-cloud-anothersimpleclient/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /j360-cloud-anothersimpleclient/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=anothersimpleclient 2 | spring.cloud.config.uri=http://localhost:8888 3 | -------------------------------------------------------------------------------- /j360-cloud-bus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | 4.0.0 9 | 10 | j360-cloud-bus 11 | 12 | org.springframework.cloud 13 | spring-cloud-build 14 | 1.1.0.BUILD-SNAPSHOT 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-maven-plugin 24 | 25 | 26 | 27 | maven-deploy-plugin 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.cloud 38 | spring-cloud-starter-bus-amqp 39 | 1.1.0.BUILD-SNAPSHOT 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-actuator 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-feign 48 | 1.0.0.BUILD-SNAPSHOT 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | true 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-test 58 | test 59 | 60 | 61 | 62 | 63 | 64 | 65 | spring-snapshots 66 | Spring Snapshots 67 | http://repo.spring.io/libs-snapshot-local 68 | 69 | true 70 | 71 | 72 | 73 | spring-milestones 74 | Spring Milestones 75 | http://repo.spring.io/libs-milestone-local 76 | 77 | false 78 | 79 | 80 | 81 | spring-releases 82 | Spring Releases 83 | http://repo.spring.io/libs-release-local 84 | 85 | false 86 | 87 | 88 | 89 | 90 | 91 | spring-snapshots 92 | Spring Snapshots 93 | http://repo.spring.io/libs-snapshot-local 94 | 95 | true 96 | 97 | 98 | 99 | spring-milestones 100 | Spring Milestones 101 | http://repo.spring.io/libs-milestone-local 102 | 103 | false 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /j360-cloud-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | j360-cloud-client 9 | 10 | 4.0.0 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-config 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-eureka 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | pl.project13.maven 50 | git-commit-id-plugin 51 | 52 | false 53 | 54 | 55 | 56 | 57 | maven-deploy-plugin 58 | 59 | true 60 | 61 | 62 | 63 | 64 | 65 | 66 | spring-snapshots 67 | Spring Snapshots 68 | http://repo.spring.io/libs-snapshot-local 69 | 70 | true 71 | 72 | 73 | 74 | spring-milestones 75 | Spring Milestones 76 | http://repo.spring.io/libs-milestone-local 77 | 78 | false 79 | 80 | 81 | 82 | spring-releases 83 | Spring Releases 84 | http://repo.spring.io/libs-release-local 85 | 86 | false 87 | 88 | 89 | 90 | 91 | 92 | spring-snapshots 93 | Spring Snapshots 94 | http://repo.spring.io/libs-snapshot-local 95 | 96 | true 97 | 98 | 99 | 100 | spring-milestones 101 | Spring Milestones 102 | http://repo.spring.io/libs-milestone-local 103 | 104 | false 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /j360-cloud-client/src/main/java/me/j360/cloud/client/Application.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.builder.SpringApplicationBuilder; 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.cloud.context.environment.EnvironmentChangeEvent; 10 | import org.springframework.context.ApplicationContext; 11 | import org.springframework.context.ConfigurableApplicationContext; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.core.env.*; 15 | import org.springframework.scheduling.annotation.EnableScheduling; 16 | import org.springframework.scheduling.annotation.Scheduled; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RestController; 19 | import org.springframework.web.context.support.StandardServletEnvironment; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | * Created with j360-cloud-all -> me.j360.cloud.client. 25 | * User: min_xu 26 | * Date: 2015/9/30 27 | * Time: 11:03 28 | * 说明: 29 | */ 30 | 31 | @SpringBootApplication 32 | @EnableScheduling 33 | //@EnableEurekaClient 34 | public class Application { 35 | 36 | @Autowired 37 | private org.springframework.cloud.context.scope.refresh.RefreshScope refreshScope; 38 | 39 | 40 | @Autowired 41 | private ConfigurationPropertiesConfig configurationPropertiesConfig; 42 | 43 | 44 | public static void main(String[] args) { 45 | SpringApplication.run(Application.class, args); 46 | } 47 | 48 | 49 | @Scheduled(cron="0/20 * * * * ? ") //每20秒执行一次 50 | public void refreshConfigProperties(){ 51 | refresh(); 52 | System.out.println(configurationPropertiesConfig.getUsername()); 53 | } 54 | 55 | private Set standardSources = new HashSet(Arrays.asList( 56 | StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, 57 | StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, 58 | StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME, 59 | StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, 60 | StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); 61 | 62 | @Autowired 63 | private ConfigurableApplicationContext context; 64 | @Autowired 65 | private org.springframework.cloud.context.scope.refresh.RefreshScope scope; 66 | 67 | /** 68 | * 手动刷新git更新方案,每20S执行一次,可以修改成手动执行,同/refresh 69 | * @link RefreshEndpoint 70 | * */ 71 | public void refresh() { 72 | Map before = extract(context.getEnvironment() 73 | .getPropertySources()); 74 | addConfigFilesToEnvironment(); 75 | Set keys = changes(before, 76 | extract(context.getEnvironment().getPropertySources())).keySet(); 77 | scope.refreshAll(); 78 | 79 | context.publishEvent(new EnvironmentChangeEvent(keys)); 80 | } 81 | @Configuration 82 | protected static class Empty { 83 | 84 | } 85 | 86 | private void addConfigFilesToEnvironment() { 87 | ConfigurableApplicationContext capture = null; 88 | try { 89 | capture = new SpringApplicationBuilder(Empty.class).showBanner(false) 90 | .web(false).environment(context.getEnvironment()).run(); 91 | MutablePropertySources target = context.getEnvironment().getPropertySources(); 92 | for (PropertySource source : capture.getEnvironment().getPropertySources()) { 93 | String name = source.getName(); 94 | if (!standardSources.contains(name)) { 95 | if (target.contains(name)) { 96 | target.replace(name, source); 97 | } 98 | else { 99 | if (target.contains("defaultProperties")) { 100 | target.addBefore("defaultProperties", source); 101 | } 102 | else { 103 | target.addLast(source); 104 | } 105 | } 106 | } 107 | } 108 | } 109 | finally { 110 | while (capture != null) { 111 | capture.close(); 112 | ApplicationContext parent = capture.getParent(); 113 | if (parent instanceof ConfigurableApplicationContext) { 114 | capture = (ConfigurableApplicationContext) parent; 115 | } else { 116 | capture = null; 117 | } 118 | } 119 | } 120 | } 121 | 122 | private Map changes(Map before, 123 | Map after) { 124 | Map result = new HashMap(); 125 | for (String key : before.keySet()) { 126 | if (!after.containsKey(key)) { 127 | result.put(key, null); 128 | } 129 | else if (!equal(before.get(key), after.get(key))) { 130 | result.put(key, after.get(key)); 131 | } 132 | } 133 | for (String key : after.keySet()) { 134 | if (!before.containsKey(key)) { 135 | result.put(key, after.get(key)); 136 | } 137 | } 138 | return result; 139 | } 140 | 141 | private boolean equal(Object one, Object two) { 142 | if (one == null && two == null) { 143 | return true; 144 | } 145 | if (one == null || two == null) { 146 | return false; 147 | } 148 | return one.equals(two); 149 | } 150 | 151 | private Map extract(MutablePropertySources propertySources) { 152 | Map result = new HashMap(); 153 | for (PropertySource parent : propertySources) { 154 | if (!standardSources.contains(parent.getName())) { 155 | extract(parent, result); 156 | } 157 | } 158 | return result; 159 | } 160 | 161 | private void extract(PropertySource parent, Map result) { 162 | if (parent instanceof CompositePropertySource) { 163 | try { 164 | for (PropertySource source : ((CompositePropertySource) parent) 165 | .getPropertySources()) { 166 | extract(source, result); 167 | } 168 | } 169 | catch (Exception e) { 170 | return; 171 | } 172 | } 173 | else if (parent instanceof EnumerablePropertySource) { 174 | for (String key : ((EnumerablePropertySource) parent).getPropertyNames()) { 175 | result.put(key, parent.getProperty(key)); 176 | } 177 | } 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /j360-cloud-client/src/main/java/me/j360/cloud/client/ConfigurationPropertiesConfig.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.client; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.stereotype.Component; 7 | 8 | 9 | /** 10 | * Created with springbootweb -> me.j360.springboot.simple.bean.config. 11 | * User: min_xu 12 | * Date: 2015/7/29 13 | * Time: 13:50 14 | * 说明:另一种配置方法 15 | */ 16 | 17 | @RefreshScope 18 | @Component 19 | @Configuration 20 | @ConfigurationProperties(prefix="user") 21 | public class ConfigurationPropertiesConfig { 22 | public String getUsername() { 23 | return username; 24 | } 25 | public void setUsername(String username) { 26 | this.username = username; 27 | } 28 | private String username; 29 | } 30 | -------------------------------------------------------------------------------- /j360-cloud-client/src/main/java/me/j360/cloud/client/MessageController.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * Created with j360-cloud-all -> me.j360.cloud.client. 12 | * User: min_xu 13 | * Date: 2015/10/7 14 | * Time: 22:37 15 | * 说明: 16 | */ 17 | 18 | @RestController 19 | @RefreshScope 20 | public class MessageController { 21 | 22 | @Value("${apply.message}") 23 | public String message; 24 | 25 | @Autowired 26 | private ConfigurationPropertiesConfig configurationPropertiesConfig; 27 | 28 | 29 | @RequestMapping("/") 30 | public String home() { 31 | return message; 32 | } 33 | 34 | @RequestMapping("/user") 35 | public String user() { 36 | return configurationPropertiesConfig.getUsername(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /j360-cloud-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | 3 | apply.message=local message 4 | user.username=xumin -------------------------------------------------------------------------------- /j360-cloud-client/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=client 2 | spring.cloud.config.uri=http://localhost:8888 3 | 4 | #spring.cloud.config.discovery.enabled=true 5 | -------------------------------------------------------------------------------- /j360-cloud-cluster/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | 4.0.0 9 | j360-cloud-cluster 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-build 14 | 1.1.0.BUILD-SNAPSHOT 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-maven-plugin 24 | 25 | 26 | 27 | maven-deploy-plugin 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.cloud 38 | spring-cloud-cluster-zookeeper 39 | 1.0.0.BUILD-SNAPSHOT 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-cluster-redis 44 | 1.0.0.BUILD-SNAPSHOT 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-actuator 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | true 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-test 59 | test 60 | 61 | 62 | org.apache.curator 63 | curator-test 64 | 2.8.0 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | spring-snapshots 73 | Spring Snapshots 74 | http://repo.spring.io/libs-snapshot-local 75 | 76 | true 77 | 78 | 79 | 80 | spring-milestones 81 | Spring Milestones 82 | http://repo.spring.io/libs-milestone-local 83 | 84 | false 85 | 86 | 87 | 88 | spring-releases 89 | Spring Releases 90 | http://repo.spring.io/libs-release-local 91 | 92 | false 93 | 94 | 95 | 96 | 97 | 98 | spring-snapshots 99 | Spring Snapshots 100 | http://repo.spring.io/libs-snapshot-local 101 | 102 | true 103 | 104 | 105 | 106 | spring-milestones 107 | Spring Milestones 108 | http://repo.spring.io/libs-milestone-local 109 | 110 | false 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /j360-cloud-cluster/src/main/java/me/j360/cloud/cluster/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.cluster; 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.cluster.lock.DistributedLock; 7 | import org.springframework.cloud.cluster.redis.lock.RedisLockService; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.data.redis.connection.RedisConnectionFactory; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.serializer.StringRedisSerializer; 12 | import org.springframework.scheduling.annotation.EnableScheduling; 13 | import org.springframework.scheduling.annotation.Scheduled; 14 | 15 | import java.util.Set; 16 | 17 | @SpringBootApplication 18 | @EnableScheduling 19 | public class ConfigServerApplication { 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ConfigServerApplication.class, args); 23 | } 24 | 25 | @Autowired 26 | private RedisConnectionFactory redisConnectionFactory; 27 | 28 | @Bean 29 | public RedisTemplate redisTemplate(){ 30 | RedisTemplate redisTemplate = new RedisTemplate(); 31 | redisTemplate.setConnectionFactory(redisConnectionFactory); 32 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 33 | redisTemplate.setValueSerializer(new StringRedisSerializer()); 34 | redisTemplate.afterPropertiesSet(); 35 | return redisTemplate; 36 | } 37 | 38 | @Bean 39 | public RedisLockService redisLockService(){ 40 | RedisLockService lockService = new RedisLockService(redisConnectionFactory); 41 | return lockService; 42 | } 43 | 44 | @Scheduled(cron="0/20 * * * * ? ") //每20秒执行一次 45 | public void refreshConfigProperties(){ 46 | //分布式锁实现 47 | cleanLocks(); 48 | DistributedLock lock = redisLockService().obtain("lock"); 49 | System.out.println(lock.getLockKey()); 50 | lock.lock(); 51 | Set keys = redisTemplate().keys(RedisLockService.DEFAULT_REGISTRY_KEY + ":*"); 52 | System.out.println(keys.size()); //1 53 | System.out.println(keys.iterator().next()); //RedisLockService.DEFAULT_REGISTRY_KEY + ":lock" 54 | lock.unlock(); 55 | cleanLocks(); 56 | 57 | //Zookeeper实现 58 | 59 | } 60 | 61 | private void cleanLocks() { 62 | Set keys = redisTemplate().keys(RedisLockService.DEFAULT_REGISTRY_KEY + ":*"); 63 | redisTemplate().delete(keys); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /j360-cloud-cluster/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring.redis.host=192.168.247.128 4 | #spring.redis.password=j360 5 | #spring.redis.port=6379 -------------------------------------------------------------------------------- /j360-cloud-cluster/src/test/java/me.j360.cloud.cluster/RedisIT.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.cluster; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.data.redis.RedisProperties; 8 | import org.springframework.boot.test.EnvironmentTestUtils; 9 | import org.springframework.cloud.cluster.lock.DistributedLock; 10 | import org.springframework.cloud.cluster.redis.lock.RedisLockService; 11 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 12 | import org.springframework.data.redis.connection.RedisConnectionFactory; 13 | import org.springframework.data.redis.core.RedisTemplate; 14 | import org.springframework.data.redis.serializer.StringRedisSerializer; 15 | 16 | import java.util.Set; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | /** 22 | * Created with j360-cloud-all -> me.j360.cloud.cluster. 23 | * User: min_xu 24 | * Date: 2015/10/12 25 | * Time: 11:19 26 | * 说明:分布式锁 27 | */ 28 | public class RedisIT { 29 | 30 | private AnnotationConfigApplicationContext context; 31 | private RedisConnectionFactory connectionFactory; 32 | private RedisTemplate redisTemplate; 33 | 34 | @Before 35 | public void setup() { 36 | context = new AnnotationConfigApplicationContext(); 37 | EnvironmentTestUtils.addEnvironment(context); 38 | context.register(RedisAutoConfiguration.class); 39 | context.refresh(); 40 | connectionFactory = context.getBean(RedisConnectionFactory.class); 41 | redisTemplate = new RedisTemplate(); 42 | redisTemplate.setConnectionFactory(connectionFactory); 43 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 44 | redisTemplate.setValueSerializer(new StringRedisSerializer()); 45 | redisTemplate.afterPropertiesSet(); 46 | cleanLocks(); 47 | } 48 | 49 | @After 50 | public void close() { 51 | cleanLocks(); 52 | context.close(); 53 | } 54 | 55 | private void cleanLocks() { 56 | Set keys = redisTemplate.keys(RedisLockService.DEFAULT_REGISTRY_KEY + ":*"); 57 | redisTemplate.delete(keys); 58 | } 59 | 60 | @Test 61 | public void testSimpleLock() { 62 | RedisLockService lockService = new RedisLockService(connectionFactory); 63 | DistributedLock lock = lockService.obtain("lock"); 64 | lock.lock(); 65 | 66 | Set keys = redisTemplate.keys(RedisLockService.DEFAULT_REGISTRY_KEY + ":*"); 67 | assertThat(keys.size(), is(1)); 68 | assertThat(keys.iterator().next(), is(RedisLockService.DEFAULT_REGISTRY_KEY + ":lock")); 69 | 70 | lock.unlock(); 71 | } 72 | 73 | @Test 74 | public void testSecondLockSucceed() { 75 | RedisLockService lockService = new RedisLockService(connectionFactory); 76 | DistributedLock lock1 = lockService.obtain("lock"); 77 | DistributedLock lock2 = lockService.obtain("lock"); 78 | lock1.lock(); 79 | // same thread so try/lock doesn't fail 80 | assertThat(lock2.tryLock(), is(true)); 81 | lock2.lock(); 82 | 83 | Set keys = redisTemplate.keys(RedisLockService.DEFAULT_REGISTRY_KEY + ":*"); 84 | assertThat(keys.size(), is(1)); 85 | assertThat(keys.iterator().next(), is(RedisLockService.DEFAULT_REGISTRY_KEY + ":lock")); 86 | 87 | lock1.unlock(); 88 | lock2.unlock(); 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /j360-cloud-cluster/src/test/java/me.j360.cloud.cluster/ZookeeperTests.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.cluster; 2 | 3 | import org.apache.curator.framework.CuratorFramework; 4 | import org.apache.curator.framework.CuratorFrameworkFactory; 5 | import org.apache.curator.retry.ExponentialBackoffRetry; 6 | import org.apache.curator.test.TestingServer; 7 | import org.junit.Test; 8 | import org.springframework.beans.factory.DisposableBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.cloud.cluster.leader.Context; 11 | import org.springframework.cloud.cluster.leader.DefaultCandidate; 12 | import org.springframework.cloud.cluster.leader.event.AbstractLeaderEvent; 13 | import org.springframework.cloud.cluster.leader.event.DefaultLeaderEventPublisher; 14 | import org.springframework.cloud.cluster.leader.event.LeaderEventPublisher; 15 | import org.springframework.cloud.cluster.zk.leader.LeaderInitiator; 16 | import org.springframework.context.ApplicationListener; 17 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | import java.io.IOException; 22 | import java.util.ArrayList; 23 | import java.util.concurrent.CountDownLatch; 24 | import java.util.concurrent.TimeUnit; 25 | 26 | import static org.hamcrest.CoreMatchers.is; 27 | import static org.junit.Assert.assertThat; 28 | 29 | /** 30 | * Created with j360-cloud-all -> me.j360.cloud.cluster. 31 | * User: min_xu 32 | * Date: 2015/10/12 33 | * Time: 11:16 34 | * 说明:zookeeper使用curator 35 | */ 36 | public class ZookeeperTests { 37 | 38 | @Test 39 | public void testSimpleLeader() throws InterruptedException { 40 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( 41 | ZkServerConfig.class, Config1.class); 42 | TestCandidate candidate = ctx.getBean(TestCandidate.class); 43 | TestEventListener listener = ctx.getBean(TestEventListener.class); 44 | assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true)); 45 | assertThat(listener.onEventLatch.await(5, TimeUnit.SECONDS), is(true)); 46 | assertThat(listener.events.size(), is(1)); 47 | ctx.close(); 48 | } 49 | 50 | @Configuration 51 | static class ZkServerConfig { 52 | 53 | @Bean 54 | public TestingServerWrapper testingServerWrapper() throws Exception { 55 | return new TestingServerWrapper(); 56 | } 57 | 58 | } 59 | 60 | @Configuration 61 | static class Config1 { 62 | 63 | @Autowired 64 | TestingServerWrapper testingServerWrapper; 65 | 66 | @Bean 67 | public TestCandidate candidate() { 68 | return new TestCandidate(); 69 | } 70 | 71 | @Bean(destroyMethod = "close") 72 | public CuratorFramework curatorClient() throws Exception { 73 | CuratorFramework client = CuratorFrameworkFactory.builder().defaultData(new byte[0]) 74 | .retryPolicy(new ExponentialBackoffRetry(1000, 3)) 75 | .connectString("localhost:" + testingServerWrapper.getPort()).build(); 76 | // for testing we start it here, thought initiator 77 | // is trying to start it if not already done 78 | client.start(); 79 | return client; 80 | } 81 | 82 | @Bean 83 | public LeaderInitiator initiator() throws Exception { 84 | LeaderInitiator initiator = new LeaderInitiator(curatorClient(), candidate()); 85 | initiator.setLeaderEventPublisher(leaderEventPublisher()); 86 | return initiator; 87 | } 88 | 89 | @Bean 90 | public LeaderEventPublisher leaderEventPublisher() { 91 | return new DefaultLeaderEventPublisher(); 92 | } 93 | 94 | @Bean 95 | public TestEventListener testEventListener() { 96 | return new TestEventListener(); 97 | } 98 | 99 | } 100 | 101 | static class TestingServerWrapper implements DisposableBean { 102 | 103 | TestingServer testingServer; 104 | 105 | public TestingServerWrapper() throws Exception { 106 | this.testingServer = new TestingServer(true); 107 | } 108 | 109 | @Override 110 | public void destroy() throws Exception { 111 | try { 112 | testingServer.close(); 113 | } 114 | catch (IOException e) { 115 | } 116 | } 117 | 118 | public int getPort() { 119 | return testingServer.getPort(); 120 | } 121 | 122 | } 123 | 124 | static class TestCandidate extends DefaultCandidate { 125 | 126 | CountDownLatch onGrantedLatch = new CountDownLatch(1); 127 | 128 | @Override 129 | public void onGranted(Context ctx) { 130 | onGrantedLatch.countDown(); 131 | super.onGranted(ctx); 132 | } 133 | 134 | } 135 | 136 | static class TestEventListener implements ApplicationListener { 137 | 138 | CountDownLatch onEventLatch = new CountDownLatch(1); 139 | 140 | ArrayList events = new ArrayList(); 141 | 142 | @Override 143 | public void onApplicationEvent(AbstractLeaderEvent event) { 144 | events.add(event); 145 | onEventLatch.countDown(); 146 | } 147 | 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /j360-cloud-configserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | j360-cloud-configserver 9 | 10 | 4.0.0 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | springcloud 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-config-server 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | 35 | 36 | 37 | 38 | com.spotify 39 | docker-maven-plugin 40 | 0.2.3 41 | 42 | ${docker.image.prefix}/${project.artifactId} 43 | src/main/docker 44 | 45 | 46 | / 47 | ${project.build.directory} 48 | ${project.build.finalName}.jar 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | pl.project13.maven 59 | git-commit-id-plugin 60 | 61 | false 62 | 63 | 64 | 65 | 66 | maven-deploy-plugin 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | spring-snapshots 77 | Spring Snapshots 78 | http://repo.spring.io/libs-snapshot-local 79 | 80 | true 81 | 82 | 83 | 84 | spring-milestones 85 | Spring Milestones 86 | http://repo.spring.io/libs-milestone-local 87 | 88 | false 89 | 90 | 91 | 92 | spring-releases 93 | Spring Releases 94 | http://repo.spring.io/libs-release-local 95 | 96 | false 97 | 98 | 99 | 100 | 101 | 102 | spring-snapshots 103 | Spring Snapshots 104 | http://repo.spring.io/libs-snapshot-local 105 | 106 | true 107 | 108 | 109 | 110 | spring-milestones 111 | Spring Milestones 112 | http://repo.spring.io/libs-milestone-local 113 | 114 | false 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /j360-cloud-configserver/src/main/java/me/j360/cloud/configserver/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.configserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ConfigServerApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /j360-cloud-configserver/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 2 | 3 | spring.cloud.config.server.git.uri=https://github.com/xuminwlt/config-repo 4 | -------------------------------------------------------------------------------- /j360-cloud-configserver/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=configserver 2 | 3 | spring.cloud.config.uri=http://localhost:8888 4 | -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | 4.0.0 9 | j360-cloud-eurekaclient 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | springcloud 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-hystrix 31 | 32 | 33 | org.springframework.cloud 34 | spring-cloud-starter-hystrix-dashboard 35 | 36 | 37 | org.springframework.cloud 38 | spring-cloud-config-client 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-starter-eureka 43 | 44 | 45 | org.springframework.cloud 46 | spring-cloud-starter-feign 47 | 48 | 49 | org.springframework.cloud 50 | spring-cloud-starter-ribbon 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | com.spotify 59 | docker-maven-plugin 60 | 0.2.3 61 | 62 | ${docker.image.prefix}/${project.artifactId} 63 | src/main/docker 64 | 65 | 66 | / 67 | ${project.build.directory} 68 | ${project.build.finalName}.jar 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-maven-plugin 76 | 77 | 78 | pl.project13.maven 79 | git-commit-id-plugin 80 | 81 | false 82 | 83 | 84 | 85 | 86 | maven-deploy-plugin 87 | 88 | true 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | spring-snapshots 97 | Spring Snapshots 98 | http://repo.spring.io/libs-snapshot-local 99 | 100 | true 101 | 102 | 103 | 104 | spring-milestones 105 | Spring Milestones 106 | http://repo.spring.io/libs-milestone-local 107 | 108 | false 109 | 110 | 111 | 112 | spring-releases 113 | Spring Releases 114 | http://repo.spring.io/libs-release-local 115 | 116 | false 117 | 118 | 119 | 120 | 121 | 122 | spring-snapshots 123 | Spring Snapshots 124 | http://repo.spring.io/libs-snapshot-local 125 | 126 | true 127 | 128 | 129 | 130 | spring-milestones 131 | Spring Milestones 132 | http://repo.spring.io/libs-milestone-local 133 | 134 | false 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/src/main/java/me/j360/cloud/eurekaclient/EurekaClientApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekaclient; 2 | 3 | import me.j360.cloud.eurekaclient.feign.HelloClient; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 9 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 10 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | 13 | 14 | @SpringBootApplication 15 | @EnableEurekaClient 16 | @EnableFeignClients 17 | @EnableHystrix 18 | public class EurekaClientApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(EurekaClientApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/src/main/java/me/j360/cloud/eurekaclient/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekaclient.controller; 2 | 3 | import me.j360.cloud.eurekaclient.feign.HelloClient; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Created with j360-cloud-all -> me.j360.cloud.eurekaclient.controller. 11 | * User: min_xu 12 | * Date: 2015/10/9 13 | * Time: 10:53 14 | * 说明: 15 | */ 16 | 17 | @RestController 18 | public class HelloController { 19 | 20 | @Autowired 21 | @Qualifier("helloClient") 22 | HelloClient client; 23 | 24 | @Autowired 25 | @Qualifier("hystrixHelloClient") 26 | HelloClient hytrixClient; 27 | 28 | /** 29 | * 直接调用feign,feign会去调用eurekaService 30 | * */ 31 | @RequestMapping("/") 32 | public String hello() { 33 | return client.hello(); 34 | } 35 | 36 | /** 37 | * 1、调用hytrix 38 | * 2、hytrix继承并调用feign 39 | * 3、feign会去调用eurekaService 40 | * */ 41 | @RequestMapping("/hytrix") 42 | public String hytrixHello() { 43 | return hytrixClient.hello(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/src/main/java/me/j360/cloud/eurekaclient/feign/HelloClient.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekaclient.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 with j360-cloud-all -> me.j360.cloud.eurekaclient.feign. 10 | * User: min_xu 11 | * Date: 2015/10/9 12 | * Time: 10:49 13 | * 说明:映射到service中的hello rest,在controller中直接调用helloClient即可 14 | */ 15 | 16 | @FeignClient("eurekaservice") 17 | public interface HelloClient { 18 | @RequestMapping(value = "/", method = GET) 19 | String hello(); 20 | } -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/src/main/java/me/j360/cloud/eurekaclient/hytrix/HystrixWrappedHelloClient.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekaclient.hytrix; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import me.j360.cloud.eurekaclient.feign.HelloClient; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service("hystrixHelloClient") 10 | public class HystrixWrappedHelloClient implements HelloClient { 11 | 12 | @Autowired 13 | @Qualifier("helloClient") 14 | private HelloClient feignHelloClient; 15 | 16 | @Override 17 | @HystrixCommand(groupKey = "helloGroup", fallbackMethod = "fallBackCall") 18 | public String hello() { 19 | return this.feignHelloClient.hello(); 20 | } 21 | 22 | public String fallBackCall() { 23 | String fallback = ("FAILED SERVICE CALL! - FALLING BACK"); 24 | return fallback; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /j360-cloud-eurekaclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | --- 2 | server: 3 | port: 8080 4 | 5 | spring: 6 | application: 7 | name: eurekaclient 8 | cloud: 9 | config: 10 | enabled: true 11 | uri: http://localhost:8888 12 | 13 | eureka: 14 | instance: 15 | leaseRenewalIntervalInSeconds: 10 16 | metadataMap: 17 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}} 18 | client: 19 | registerWithEureka: true 20 | fetchRegistry: true 21 | serviceUrl: 22 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /j360-cloud-eurekadashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | 4.0.0 9 | j360-cloud-eurekadashboard 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | springcloud 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-hystrix-dashboard 31 | 32 | 33 | org.springframework.cloud 34 | spring-cloud-starter-turbine 35 | 36 | 37 | 38 | 39 | 40 | 41 | com.spotify 42 | docker-maven-plugin 43 | 0.2.3 44 | 45 | ${docker.image.prefix}/${project.artifactId} 46 | src/main/docker 47 | 48 | 49 | / 50 | ${project.build.directory} 51 | ${project.build.finalName}.jar 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | pl.project13.maven 62 | git-commit-id-plugin 63 | 64 | false 65 | 66 | 67 | 68 | 69 | maven-deploy-plugin 70 | 71 | true 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | spring-snapshots 80 | Spring Snapshots 81 | http://repo.spring.io/libs-snapshot-local 82 | 83 | true 84 | 85 | 86 | 87 | spring-milestones 88 | Spring Milestones 89 | http://repo.spring.io/libs-milestone-local 90 | 91 | false 92 | 93 | 94 | 95 | spring-releases 96 | Spring Releases 97 | http://repo.spring.io/libs-release-local 98 | 99 | false 100 | 101 | 102 | 103 | 104 | 105 | spring-snapshots 106 | Spring Snapshots 107 | http://repo.spring.io/libs-snapshot-local 108 | 109 | true 110 | 111 | 112 | 113 | spring-milestones 114 | Spring Milestones 115 | http://repo.spring.io/libs-milestone-local 116 | 117 | false 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /j360-cloud-eurekadashboard/src/main/java/me/j360/cloud/eurekadashboard/DashboardApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekadashboard; 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 | @SpringBootApplication 10 | @EnableEurekaClient 11 | @EnableHystrixDashboard 12 | @EnableTurbine 13 | public class DashboardApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(DashboardApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /j360-cloud-eurekadashboard/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | --- 2 | server: 3 | port: 8989 4 | 5 | spring: 6 | application: 7 | name: eurekadashboard 8 | cloud: 9 | config: 10 | enabled: true 11 | uri: http://localhost:8888 12 | 13 | eureka: 14 | instance: 15 | leaseRenewalIntervalInSeconds: 10 16 | metadataMap: 17 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}} 18 | client: 19 | registerWithEureka: true 20 | fetchRegistry: true 21 | serviceUrl: 22 | defaultZone: http://localhost:8761/eureka/ 23 | 24 | turbine: 25 | aggregator: 26 | clusterConfig: eurekaclient -------------------------------------------------------------------------------- /j360-cloud-eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | j360-cloud-eurekaserver 9 | 4.0.0 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-starter-parent 14 | Angel.SR3 15 | 16 | 17 | 18 | UTF-8 19 | 1.7 20 | springcloud 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter-config 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-eureka-server 31 | 32 | 33 | 34 | 35 | 36 | 37 | com.spotify 38 | docker-maven-plugin 39 | 0.2.3 40 | 41 | ${docker.image.prefix}/${project.artifactId} 42 | src/main/docker 43 | 44 | 45 | / 46 | ${project.build.directory} 47 | ${project.build.finalName}.jar 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | pl.project13.maven 58 | git-commit-id-plugin 59 | 60 | false 61 | 62 | 63 | 64 | 65 | maven-deploy-plugin 66 | 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | spring-snapshots 76 | Spring Snapshots 77 | http://repo.spring.io/libs-snapshot-local 78 | 79 | true 80 | 81 | 82 | 83 | spring-milestones 84 | Spring Milestones 85 | http://repo.spring.io/libs-milestone-local 86 | 87 | false 88 | 89 | 90 | 91 | spring-releases 92 | Spring Releases 93 | http://repo.spring.io/libs-release-local 94 | 95 | false 96 | 97 | 98 | 99 | 100 | 101 | spring-snapshots 102 | Spring Snapshots 103 | http://repo.spring.io/libs-snapshot-local 104 | 105 | true 106 | 107 | 108 | 109 | spring-milestones 110 | Spring Milestones 111 | http://repo.spring.io/libs-milestone-local 112 | 113 | false 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /j360-cloud-eurekaserver/src/main/java/me/j360/cloud/eurekaserver/EurekaApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.eurekaserver; 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.eureka.server.EnableEurekaServer; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaServer 10 | @EnableEurekaClient 11 | public class EurekaApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(EurekaApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /j360-cloud-eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | --- 2 | server: 3 | port: 8761 4 | 5 | spring: 6 | application: 7 | name:eurekaserver 8 | cloud: 9 | config: 10 | uri:http://localhost:8888 11 | 12 | eureka: 13 | instance: 14 | hostname: localhost 15 | client: 16 | registerWithEureka: false 17 | fetchRegistry: false 18 | serviceUrl: 19 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /j360-cloud-eurekaservice/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | me.j360.cloud.all 6 | 1.0-SNAPSHOT 7 | 4.0.0 8 | j360-cloud-eurekaservice 9 | 10 | 11 | org.springframework.cloud 12 | spring-cloud-starter-parent 13 | Angel.SR3 14 | 15 | 16 | 17 | UTF-8 18 | 1.7 19 | springcloud 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-config-client 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-eureka 34 | 35 | 36 | 37 | 38 | 39 | 40 | com.spotify 41 | docker-maven-plugin 42 | 0.2.3 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 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | pl.project13.maven 61 | git-commit-id-plugin 62 | 63 | false 64 | 65 | 66 | 67 | 68 | maven-deploy-plugin 69 | 70 | true 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | spring-snapshots 79 | Spring Snapshots 80 | http://repo.spring.io/libs-snapshot-local 81 | 82 | true 83 | 84 | 85 | 86 | spring-milestones 87 | Spring Milestones 88 | http://repo.spring.io/libs-milestone-local 89 | 90 | false 91 | 92 | 93 | 94 | spring-releases 95 | Spring Releases 96 | http://repo.spring.io/libs-release-local 97 | 98 | false 99 | 100 | 101 | 102 | 103 | 104 | spring-snapshots 105 | Spring Snapshots 106 | http://repo.spring.io/libs-snapshot-local 107 | 108 | true 109 | 110 | 111 | 112 | spring-milestones 113 | Spring Milestones 114 | http://repo.spring.io/libs-milestone-local 115 | 116 | false 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /j360-cloud-eurekaservice/src/main/java/me/j360/cloud/erurekaservice/ServiceApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.erurekaservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ServiceApplication { 10 | public static void main(String[] args) { 11 | SpringApplication.run(ServiceApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /j360-cloud-eurekaservice/src/main/java/me/j360/cloud/erurekaservice/controller/ServiceController.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.erurekaservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.client.ServiceInstance; 5 | import org.springframework.cloud.client.discovery.DiscoveryClient; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class ServiceController { 11 | 12 | @Autowired 13 | DiscoveryClient client; 14 | 15 | @RequestMapping("/") 16 | public String hello() { 17 | ServiceInstance localInstance = client.getLocalServiceInstance(); 18 | return "Hello World: "+ localInstance.getServiceId()+":"+localInstance.getHost()+":"+localInstance.getPort(); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /j360-cloud-eurekaservice/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | --- 2 | server: 3 | port: 8082 4 | 5 | spring: 6 | application: 7 | name: eurekaservice 8 | cloud: 9 | config: 10 | enabled: true 11 | uri: http://localhost:8888 12 | 13 | eureka: 14 | instance: 15 | leaseRenewalIntervalInSeconds: 10 16 | metadataMap: 17 | instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}} 18 | client: 19 | registerWithEureka: true 20 | fetchRegistry: true 21 | serviceUrl: 22 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /j360-cloud-zookeeperclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | me.j360.cloud.all 7 | 1.0-SNAPSHOT 8 | 4.0.0 9 | j360-cloud-zookeeperclient 10 | 11 | 12 | org.springframework.cloud 13 | spring-cloud-build 14 | 1.1.0.BUILD-SNAPSHOT 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-maven-plugin 24 | 25 | 26 | 27 | maven-deploy-plugin 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.cloud 38 | spring-cloud-starter-zookeeper-all 39 | 1.0.0.BUILD-SNAPSHOT 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-actuator 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-feign 48 | 1.0.0.BUILD-SNAPSHOT 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | true 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-test 58 | test 59 | 60 | 61 | 62 | 63 | 64 | 65 | spring-snapshots 66 | Spring Snapshots 67 | http://repo.spring.io/libs-snapshot-local 68 | 69 | true 70 | 71 | 72 | 73 | spring-milestones 74 | Spring Milestones 75 | http://repo.spring.io/libs-milestone-local 76 | 77 | false 78 | 79 | 80 | 81 | spring-releases 82 | Spring Releases 83 | http://repo.spring.io/libs-release-local 84 | 85 | false 86 | 87 | 88 | 89 | 90 | 91 | spring-snapshots 92 | Spring Snapshots 93 | http://repo.spring.io/libs-snapshot-local 94 | 95 | true 96 | 97 | 98 | 99 | spring-milestones 100 | Spring Milestones 101 | http://repo.spring.io/libs-milestone-local 102 | 103 | false 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /j360-cloud-zookeeperclient/src/main/java/me/j360/cloud/zookeeperclient/ZookeeperApplication.java: -------------------------------------------------------------------------------- 1 | package me.j360.cloud.zookeeperclient; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.boot.bind.RelaxedPropertyResolver; 8 | import org.springframework.cloud.client.ServiceInstance; 9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 10 | import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; 11 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 12 | import org.springframework.cloud.netflix.feign.FeignClient; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.core.env.Environment; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestMethod; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | /** 21 | * Created with j360-cloud-all -> me.j360.cloud.zookeeperclient. 22 | * User: min_xu 23 | * Date: 2015/10/9 24 | * Time: 21:54 25 | * 说明:zookeeper还未正式发布 bug较多,作为discovery service服务时,使用@EnableDiscoveryClient 26 | * zookeeper仅仅是作为数据存储的地方,同eureka一样,但是eureka简单很多,目前推荐eureka 27 | */ 28 | @Configuration 29 | @EnableAutoConfiguration 30 | @EnableDiscoveryClient 31 | @RestController 32 | @EnableFeignClients 33 | public class ZookeeperApplication { 34 | 35 | @Value("${spring.application.name:testZookeeperApp}") 36 | private String appName; 37 | 38 | @Autowired 39 | private LoadBalancerClient loadBalancer; 40 | 41 | @Autowired 42 | private Environment env; 43 | 44 | @Autowired 45 | private AppClient appClient; 46 | 47 | @RequestMapping("/") 48 | public ServiceInstance lb() { 49 | return loadBalancer.choose(appName); 50 | } 51 | 52 | @RequestMapping("/hi") 53 | public String hi() { 54 | return "Hello World!"; 55 | } 56 | 57 | @RequestMapping("/self") 58 | public String self() { 59 | return appClient.hi(); 60 | } 61 | 62 | @RequestMapping("/myenv") 63 | public String env(@RequestParam("prop") String prop) { 64 | String property = new RelaxedPropertyResolver(env).getProperty(prop, "Not Found"); 65 | return property; 66 | } 67 | 68 | @FeignClient("testZookeeperApp") 69 | interface AppClient { 70 | @RequestMapping(value = "/hi", method = RequestMethod.GET) 71 | String hi(); 72 | } 73 | 74 | public static void main(String[] args) { 75 | SpringApplication.run(ZookeeperApplication.class, args); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /j360-cloud-zookeeperclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | endpoints: 5 | restart: 6 | enabled: true 7 | shutdown: 8 | enabled: true 9 | health: 10 | sensitive: false 11 | 12 | logging.level: 13 | org.apache.zookeeper.ClientCnxn: WARN 14 | 15 | #spring.cloud.zookeeper.dependencies: 16 | # - testZookeeperApp: ~ -------------------------------------------------------------------------------- /j360-cloud-zookeeperclient/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: testZookeeperApp 4 | cloud: 5 | zookeeper: 6 | enabled: true 7 | connectString: 192.168.247.128:2181 8 | config: 9 | # TODO: refactor spring-cloud-config to use refresh, etc.. with out config client 10 | enabled: false 11 | -------------------------------------------------------------------------------- /j360-cloud-zookeeperclient/src/test/java/me/j360/cloud/zookeeperclient/SampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package me.j360.cloud.zookeeperclient; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.springframework.boot.test.SpringApplicationConfiguration; 22 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @SpringApplicationConfiguration(classes = ZookeeperApplication.class) 26 | public class SampleApplicationTests { 27 | 28 | @Test 29 | public void contextLoads() {} 30 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.j360.cloud.all 8 | j360-cloud-all 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | j360-cloud-client 13 | j360-cloud-configserver 14 | j360-cloud-anothersimpleclient 15 | j360-cloud-eurekaserver 16 | j360-cloud-eurekaservice 17 | j360-cloud-eurekaclient 18 | j360-cloud-eurekadashboard 19 | j360-cloud-zookeeperclient 20 | j360-cloud-cluster 21 | j360-cloud-bus 22 | 23 | 24 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-parent 34 | 1.4.0.RELEASE 35 | 36 | 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-dependencies 41 | Camden.SR2 42 | pom 43 | import 44 | 45 | 46 | 47 | 48 | 49 | 50 | UTF-8 51 | demo.ConfigServerApplication 52 | 1.7 53 | springcloud 54 | 55 | 56 | 57 | 58 | com.spotify 59 | docker-maven-plugin 60 | 0.2.3 61 | 62 | ${docker.image.prefix}/${project.artifactId} 63 | src/main/docker 64 | 65 | 66 | / 67 | ${project.build.directory} 68 | ${project.build.finalName}.jar 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-maven-plugin 76 | 77 | 78 | pl.project13.maven 79 | git-commit-id-plugin 80 | 81 | false 82 | 83 | 84 | 85 | 86 | maven-deploy-plugin 87 | 88 | true 89 | 90 | 91 | 92 | 93 | 94 | 95 | org.springframework.cloud 96 | spring-cloud-starter-config 97 | 98 | 99 | org.springframework.cloud 100 | spring-cloud-starter-eureka 101 | 102 | 103 | 104 | 105 | 106 | spring-snapshots 107 | Spring Snapshots 108 | http://repo.spring.io/libs-snapshot-local 109 | 110 | true 111 | 112 | 113 | 114 | spring-milestones 115 | Spring Milestones 116 | http://repo.spring.io/libs-milestone-local 117 | 118 | false 119 | 120 | 121 | 122 | spring-releases 123 | Spring Releases 124 | http://repo.spring.io/libs-release-local 125 | 126 | false 127 | 128 | 129 | 130 | 131 | 132 | spring-snapshots 133 | Spring Snapshots 134 | http://repo.spring.io/libs-snapshot-local 135 | 136 | true 137 | 138 | 139 | 140 | spring-milestones 141 | Spring Milestones 142 | http://repo.spring.io/libs-milestone-local 143 | 144 | false 145 | 146 | 147 | 148 | --------------------------------------------------------------------------------