diff --git a/auth-service/pom.xml b/auth-service/pom.xml index 2b317b0e..e2f71e90 100644 --- a/auth-service/pom.xml +++ b/auth-service/pom.xml @@ -33,7 +33,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery diff --git a/config-repo/application.yml b/config-repo/application.yml index fffb14a5..c57b2edf 100644 --- a/config-repo/application.yml +++ b/config-repo/application.yml @@ -1,11 +1,3 @@ -eureka: - instance: - hostname: registry - prefer-ip-address: true - client: - service-url: - defaultZone: http://user:${REGISTRY_SERVER_PASSWORD:password}@registry:8761/eureka/ - hystrix: command: default: @@ -19,6 +11,13 @@ ribbon: ConnectTimeout: 5000 spring: + cloud: + consul: + discovery: + prefer-ip-address: true + instance-id: ${spring.application.name}:${server.port}:${random.value} + host: registry + port: 8500 rabbitmq: host: rabbitmq sleuth: @@ -30,9 +29,9 @@ spring: skip-pattern: "^org.*HystrixStreamTask$" authserver: - hostname: auth-service - port: 5000 - contextPath: /uaa + hostname: auth-service + port: 5000 + contextPath: /uaa security: oauth2: diff --git a/config-repo/auth-service.yml b/config-repo/auth-service.yml index 63d49110..f36efea6 100644 --- a/config-repo/auth-service.yml +++ b/config-repo/auth-service.yml @@ -7,14 +7,12 @@ management: enabled: false context-path: /mgmt -eureka: - instance: - health-check-url-path: ${server.context-path}${management.context-path}/health - status-page-url-path: ${server.context-path}${management.context-path}/info - metadata-map: - management.context-path: ${server.context-path}${management.context-path} - spring: + cloud: + consul: + discovery: + health-check-path: ${server.context-path}${management.context-path}/health + tags: management.context-path=${server.context-path}${management.context-path} datasource: url: jdbc:h2:mem:user driver-class-name: org.h2.Driver diff --git a/config-repo/svca-service.yml b/config-repo/svca-service.yml index aee0998d..dc0e009b 100644 --- a/config-repo/svca-service.yml +++ b/config-repo/svca-service.yml @@ -3,11 +3,11 @@ server: name: zhangxd -eureka: - instance: - metadata-map: - user.name: ${security.user.name} - user.password: ${security.user.password} +spring: + cloud: + consul: + discovery: + tags: user.name=${security.user.name}, user.password=${security.user.password} security: user: diff --git a/config-repo/svcb-service.yml b/config-repo/svcb-service.yml index 337fca95..e3dc5e51 100644 --- a/config-repo/svcb-service.yml +++ b/config-repo/svcb-service.yml @@ -3,11 +3,11 @@ server: msg: Hello -eureka: - instance: - metadata-map: - user.name: ${security.user.name} - user.password: ${security.user.password} +spring: + cloud: + consul: + discovery: + tags: user.name=${security.user.name}, user.password=${security.user.password} security: user: diff --git a/config/pom.xml b/config/pom.xml index 3cc4574c..d1594395 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -30,7 +30,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery org.springframework.boot diff --git a/config/src/main/resources/application.yml b/config/src/main/resources/application.yml index 373c2a87..c9333630 100644 --- a/config/src/main/resources/application.yml +++ b/config/src/main/resources/application.yml @@ -1,24 +1,20 @@ server: port: 8888 -eureka: - instance: - hostname: registry - prefer-ip-address: true - metadata-map: - user.name: ${security.user.name} - user.password: ${security.user.password} - client: - service-url: - defaultZone: http://user:${REGISTRY_SERVER_PASSWORD:password}@registry:8761/eureka/ - spring: cloud: + consul: + discovery: + prefer-ip-address: true + tags: user.name=${security.user.name}, user.password=${security.user.password} + host: registry + port: 8500 config: server: git: uri: https://github.com/zhangxd1989/spring-boot-cloud search-paths: config-repo + default-label: consul rabbitmq: host: rabbitmq diff --git a/docker-compose.yml b/docker-compose.yml index ab328554..e6bc539c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,16 @@ version: '2' services: rabbitmq: - image: rabbitmq:3-management - restart: always - ports: - - 15673:15672 + image: rabbitmq:3-management + restart: always + ports: + - "15673:15672" registry: - image: spring-boot-cloud/registry + image: consul ports: - - "8761:8761" + - "8400:8400" + - "8500:8500" + - "8600:8600" config: image: spring-boot-cloud/config ports: diff --git a/gateway/pom.xml b/gateway/pom.xml index dc76a1ec..bc123f1c 100644 --- a/gateway/pom.xml +++ b/gateway/pom.xml @@ -26,7 +26,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery org.springframework.cloud diff --git a/monitor/pom.xml b/monitor/pom.xml index 95d434bf..f9859b35 100644 --- a/monitor/pom.xml +++ b/monitor/pom.xml @@ -40,6 +40,10 @@ org.springframework.cloud spring-cloud-starter-turbine-stream + + org.springframework.cloud + spring-cloud-starter-eureka + netty-transport-native-epoll io.netty @@ -56,7 +60,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery org.springframework.boot diff --git a/monitor/src/main/resources/application.yml b/monitor/src/main/resources/application.yml index f4b16fd2..c51e5c67 100644 --- a/monitor/src/main/resources/application.yml +++ b/monitor/src/main/resources/application.yml @@ -9,18 +9,14 @@ turbine: stream: port: 8041 -eureka: - instance: - hostname: registry - prefer-ip-address: true - metadata-map: - user.name: ${security.user.name} - user.password: ${security.user.password} - client: - service-url: - defaultZone: http://user:${REGISTRY_SERVER_PASSWORD:password}@registry:8761/eureka/ - spring: + cloud: + consul: + discovery: + prefer-ip-address: true + tags: user.name=${security.user.name}, user.password=${security.user.password} + host: registry + port: 8500 rabbitmq: host: rabbitmq boot: @@ -30,6 +26,8 @@ spring: turbine: clusters: default location: http://monitor:${turbine.stream.port} + discovery: + ignored-services: consul security: user: diff --git a/pom.xml b/pom.xml index 9e5de967..644b1e6d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,6 @@ config - registry gateway monitor auth-service @@ -33,7 +32,7 @@ 1.8 0.4.13 spring-boot-cloud - Dalston.RELEASE + Dalston.SR1 1.5.0 diff --git a/registry/Dockerfile b/registry/Dockerfile deleted file mode 100644 index 9a6f58f1..00000000 --- a/registry/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM java:8 -VOLUME /tmp -ADD ./target/registry.jar /app.jar -RUN bash -c 'touch /app.jar' -EXPOSE 8761 -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/registry/pom.xml b/registry/pom.xml deleted file mode 100644 index 8c62482b..00000000 --- a/registry/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - 4.0.0 - - - cn.zhangxd - spring-boot-cloud - 1.0-SNAPSHOT - - - registry - 1.0-SNAPSHOT - jar - ${project.artifactId} - - - - org.springframework.cloud - spring-cloud-starter-eureka-server - - - org.springframework.boot - spring-boot-starter-security - - - - - ${project.artifactId} - - - org.springframework.boot - spring-boot-maven-plugin - - - com.spotify - docker-maven-plugin - - - - \ No newline at end of file diff --git a/registry/src/main/java/cn/zhangxd/registry/RegistryApplication.java b/registry/src/main/java/cn/zhangxd/registry/RegistryApplication.java deleted file mode 100644 index a3b9e847..00000000 --- a/registry/src/main/java/cn/zhangxd/registry/RegistryApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.zhangxd.registry; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; - -@SpringBootApplication -@EnableEurekaServer -public class RegistryApplication { - - public static void main(String[] args) { - SpringApplication.run(RegistryApplication.class, args); - } -} diff --git a/registry/src/main/resources/application.yml b/registry/src/main/resources/application.yml deleted file mode 100644 index 4927b884..00000000 --- a/registry/src/main/resources/application.yml +++ /dev/null @@ -1,17 +0,0 @@ -server: - port: 8761 - -eureka: - instance: - hostname: registry - prefer-ip-address: true - client: - registerWithEureka: false - fetchRegistry: false - service-url: - defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/ - -security: - user: - name: user - password: ${REGISTRY_SERVER_PASSWORD:password} diff --git a/registry/src/main/resources/bootstrap.yml b/registry/src/main/resources/bootstrap.yml deleted file mode 100644 index a65daee8..00000000 --- a/registry/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - application: - name: registry \ No newline at end of file diff --git a/registry/src/test/java/cn/zhangxd/registry/ApplicationTests.java b/registry/src/test/java/cn/zhangxd/registry/ApplicationTests.java deleted file mode 100644 index 369fd5e3..00000000 --- a/registry/src/test/java/cn/zhangxd/registry/ApplicationTests.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.zhangxd.registry; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) -public class ApplicationTests { - - @Autowired - private TestRestTemplate testRestTemplate; - @Value("${security.user.name}") - private String username; - @Value("${security.user.password}") - private String password; - - @Test - public void catalogLoads() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = - testRestTemplate - .withBasicAuth(username, password) - .getForEntity("/eureka/apps", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - } - - @Test - public void adminLoads() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = - testRestTemplate - .withBasicAuth(username, password) - .getForEntity("/env", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - } - -} \ No newline at end of file diff --git a/svca-service/pom.xml b/svca-service/pom.xml index 4924cd65..539cccfc 100644 --- a/svca-service/pom.xml +++ b/svca-service/pom.xml @@ -23,7 +23,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery diff --git a/svca-service/src/main/java/cn/zhangxd/svca/controller/ServiceAController.java b/svca-service/src/main/java/cn/zhangxd/svca/controller/ServiceAController.java index 5ca6c56a..99e13d72 100644 --- a/svca-service/src/main/java/cn/zhangxd/svca/controller/ServiceAController.java +++ b/svca-service/src/main/java/cn/zhangxd/svca/controller/ServiceAController.java @@ -4,8 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient; import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -19,7 +19,8 @@ public class ServiceAController { private String name; @Autowired - EurekaDiscoveryClient discoveryClient; + ConsulDiscoveryClient discoveryClient; + @Autowired private ServiceBClient serviceBClient; diff --git a/svcb-service/pom.xml b/svcb-service/pom.xml index a11c72a2..918959bd 100644 --- a/svcb-service/pom.xml +++ b/svcb-service/pom.xml @@ -23,7 +23,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-consul-discovery diff --git a/svcb-service/src/main/java/cn/zhangxd/svcb/controller/ServiceBController.java b/svcb-service/src/main/java/cn/zhangxd/svcb/controller/ServiceBController.java index 573a8cf4..e8891564 100644 --- a/svcb-service/src/main/java/cn/zhangxd/svcb/controller/ServiceBController.java +++ b/svcb-service/src/main/java/cn/zhangxd/svcb/controller/ServiceBController.java @@ -3,8 +3,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient; import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -13,7 +13,7 @@ public class ServiceBController { @Autowired - EurekaDiscoveryClient discoveryClient; + ConsulDiscoveryClient discoveryClient; @Value("${msg:unknown}") private String msg;