Skip to content

Commit

Permalink
集成配置中心
Browse files Browse the repository at this point in the history
  • Loading branch information
fp2952 committed Jun 29, 2018
1 parent daf8b1a commit ec7f365
Show file tree
Hide file tree
Showing 26 changed files with 409 additions and 127 deletions.
19 changes: 8 additions & 11 deletions api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,31 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<!--config-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<!--zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<!--RabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
</dependencies>

Expand Down
18 changes: 18 additions & 0 deletions api-gateway/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
application:
name: api-gateway
profiles:
active: dev
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true
config:
fail-fast: true
discovery:
service-id: config-server
enabled: true
profile: ${spring.profiles.active}
label: ${spring.profiles.active}
38 changes: 22 additions & 16 deletions auth-center/auth-center-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.43</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--discovery、ribbon-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
Expand All @@ -60,21 +56,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<!--security、oauth2-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>


<!--UI-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
Expand All @@ -95,6 +82,25 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--config-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>

<!--zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

</dependencies>

Expand Down
23 changes: 23 additions & 0 deletions auth-center/auth-center-provider/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spring:
application:
name: auth-center
profiles:
active: dev
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true
health-check-path: ${server.context-path}/health
tags: management.context-path=${server.context-path}
config:
fail-fast: true
discovery:
service-id: config-server
enabled: true
profile: ${spring.profiles.active}
label: ${spring.profiles.active}

server:
context-path: /auth
21 changes: 21 additions & 0 deletions config-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>config-git</artifactId>
<description>配置中心</description>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<!--配置中心服务-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.peng.config.git;

import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
* Created by fp295 on 2018/6/29.
*/
@EnableConfigServer
@SpringCloudApplication
public class ConfigServerApplication {

public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
37 changes: 37 additions & 0 deletions config-git/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
server:
port: 18006

spring:
application:
name: config-server
profiles:
active: native
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true

---
spring:
profiles: native
cloud:
config:
server:
native:
search-locations: classpath:/config/
fail-fast: true

---
spring:
profiles: prd
cloud:
config:
server:
git:
uri: https://github.com/ityouknow/spring-cloud-starter/ # 配置git仓库的地址
search-paths: config-repo # git仓库地址下的相对地址,可以配置多个,用,分割。
username: # git仓库的账号
password: # git仓库的密码

Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
spring:
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true
application:
name: api-gateway
server:
port: 18000

spring:
rabbitmq:
host: localhost
port: 5672
password: '000000'
username: fangp

zuul:
routes:
main-data:
path: /api/main-data/**
serviceId: main-data

proxy:
auth:
routes:
main-data: oauth2

security:
ignored: |
/css/**,/js/**,/favicon.ico,/webjars/**,/images/**,
Expand All @@ -28,7 +29,4 @@ security:
jwt:
key-uri: http://${AUTH_CENTER_HOST:localhost}:${AUTH_CENTER_PORT:18001}/auth/oauth/token_key
id: ${spring.application.name}
serviceId: ${spring.application.name}
management:
security:
enabled: false
serviceId: ${spring.application.name}
20 changes: 20 additions & 0 deletions config-git/src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server:
tomcat:
max-threads: 500 # Maximum amount of worker threads.
min-spare-threads: 50 # Minimum amount of worker threads


#监控短点配置
management:
security:
enabled: false
info:
git:
mode: full
endpoints:
actuator:
enabled: true
shutdown:
enabled: false
info:
version: @project.version@
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ security:
/jolokia,/configprops,/activiti,/logfile,/refresh,/flyway,/liquibase,/loggers,/druid/**,
/oauth/deleteToken, /backReferer
server:
context-path: /auth
port: 18001
spring:
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true
health-check-path: ${server.context-path}/health
tags: management.context-path=${server.context-path}
application:
name: auth-center
redis:
database: 0
host: ${REDIS_HOST:localhost}
Expand Down Expand Up @@ -52,8 +41,10 @@ spring:
login-password: "000000"
freemarker:
request-context-attribute: request
rabbitmq:
host: localhost
port: 5672
username: fangp
password: '000000'
logging:
file: logs/auth-center.log
management:
security:
enabled: false
file: logs/auth-center.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
server:
port: 18002
# 数据源配置
spring:
datasource:
Expand Down Expand Up @@ -28,14 +30,6 @@ spring:
reset-enable: false
login-username: sysadmin
login-password: "000000"
cloud:
consul:
host: ${CONSUL_HOST:localhost}
port: ${CONSUL_PORT:8500}
discovery:
prefer-ip-address: true
application:
name: main-data
redis:
database: 0
host: ${REDIS_HOST:localhost}
Expand Down Expand Up @@ -63,9 +57,4 @@ mybatis:
type-aliases-package: com.peng.main.api.mapper.model
mapper-locations: classpath:mybatis/mapper/*.xml
logging:
file: logs/main-data.log
server:
port: 18002
management:
security:
enabled: false
file: logs/main-data.log
12 changes: 12 additions & 0 deletions config-git/src/main/resources/config/mc-service-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server:
port: 18004

spring:
rabbitmq:
host: localhost
port: 5672
username: fangp
password: '000000'

logging:
file: logs/mc-service.log
Loading

0 comments on commit ec7f365

Please sign in to comment.