diff --git a/pom.xml b/pom.xml index 0b33c7d..7431d4a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,22 +1,40 @@ - + 4.0.0 org.springframework.boot spring-boot-starter-parent - 3.0.3 + 3.0.5 com.flagnote flagnote-gateway - 0.0.1-SNAPSHOT + 0.0.1 flagnote-gateway Demo project for Spring Boot 17 - 2022.0.1 + 17 + 17 + 17 + 2022.0.2 + flagnote + + org.springframework.cloud + spring-cloud-starter-zookeeper-discovery + + + org.springframework.cloud + spring-cloud-config-client + + + org.springframework.cloud + spring-cloud-starter-bootstrap + org.springframework.boot spring-boot-starter-data-redis-reactive @@ -29,12 +47,7 @@ org.springframework.cloud spring-cloud-starter-loadbalancer - + org.projectlombok lombok @@ -45,13 +58,6 @@ hutool-all 5.7.22 - - org.springframework.boot spring-boot-starter-test @@ -81,10 +87,51 @@ + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + UTF-8 + true + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + org.springframework.boot spring-boot-maven-plugin + + + com.spotify + docker-maven-plugin + + false + http://rancher:42375 + + ${docker.image.prefix}/${project.artifactId}:${project.version} + src/main/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + diff --git a/src/main/docker/dockerfile b/src/main/docker/dockerfile new file mode 100644 index 0000000..a71183b --- /dev/null +++ b/src/main/docker/dockerfile @@ -0,0 +1,8 @@ +FROM openjdk:17-slim +VOLUME /tmp +ADD flagnote-gateway-0.0.1.jar app.jar +RUN sh -c 'touch /app.jar' +RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone +RUN apt-get update && apt-get install -y curl +ENV JAVA_OPTS="" +ENTRYPOINT [ "sh", "-c", "exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] \ No newline at end of file diff --git a/src/main/java/com/flagnote/gateway/GatewayApplication.java b/src/main/java/com/flagnote/gateway/GatewayApplication.java index 2fa16c9..8a08af5 100644 --- a/src/main/java/com/flagnote/gateway/GatewayApplication.java +++ b/src/main/java/com/flagnote/gateway/GatewayApplication.java @@ -1,13 +1,17 @@ package com.flagnote.gateway; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient; import com.flagnote.gateway.config.BkrLoadBalancerConfiguration; @SpringBootApplication -@LoadBalancerClient(name = "noteCommonService", configuration = BkrLoadBalancerConfiguration.class) +@EnableAutoConfiguration +@EnableDiscoveryClient +@LoadBalancerClient(name = "flagnote-service", configuration = BkrLoadBalancerConfiguration.class) public class GatewayApplication { public static void main(String[] args) { SpringApplication.run(GatewayApplication.class, args); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 0230585..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,170 +0,0 @@ -server: -# address: 127.0.0.1 - port: 10000 -spring: - application: - name: flagnote-gateway - profiles: - active: dev -# config: -# import: 'optional:configserver:http://localhost:9999' - data: - redis: - database: 10 - host: service.flagnote.com - port: 16379 - timeout: 10000 - poolMaxTotal: 10 - poolMaxIdle: 10 - poolMaxWait: 3 - password: redis1qazx1qazx - codec: - max-in-memory-size: 10MB - servlet: - multipart: - # 最大支持文件大小 - max-file-size: 10MB - # 最大支持请求大小 - max-request-size: 10MB - - cloud: - discovery: - client: - simple: - instances: - noteCommonService: # 一定要带端口 - - uri: http://127.0.0.1:20000 - - uri: http://127.0.0.1:20001 - keyMetaService: # 一定要带端口 - - uri: http://127.0.0.1:20000 - - uri: http://127.0.0.1:20001 - - loadbalancer: - configurations: health-check - health-check: - path: - noteCommonService: /f2w8u47ie56edc93/actuator/health - keyMetaService: /f2w8u47ie56edc93/actuator/health - initial-delay: 0 - interval: 5s - inetutils: - # 指定此客户端的ip - default-ip-address: localhost - gateway: -# globalcors: -# corsConfigurations: -# '[/**]': -# allowedOrigins: "*" -# allowedMethods: "*" - routes: - - id: keyMeta - uri: lb://keyMetaService - order: -1 - predicates: - - Path=/note/keyMeta - - Method=GET - filters: - - name: RequestRateLimiter - args: - # 如果返回的key是空的话,false则不进行限流 -# deny-empty-key: true -# status-code: TOO_MANY_REQUESTS - # 每秒产生多少个令牌 - redis-rate-limiter.replenishRate: 1 - # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 - redis-rate-limiter.burstCapacity: 10 - # 每次请求申请几个令牌 - redis-rate-limiter.requestedTokens: 1 - # IP 地址限流 - key-resolver: "#{@remoteAddrKeyResolver}" - - - - name: RequestRateLimiter - args: - # 如果返回的key是空的话,false则不进行限流 -# deny-empty-key: true -# status-code: TOO_MANY_REQUESTS - # 每秒产生多少个令牌 - redis-rate-limiter.replenishRate: 1 - # 1秒内最大的令牌,即在1s内可以允许的突发流程,设置为0,表示阻止所有的请求 - redis-rate-limiter.burstCapacity: 10 - # 每次请求申请几个令牌 - redis-rate-limiter.requestedTokens: 2 - # IP 地址限流 - key-resolver: "#{@remoteSessionKeyResolver}" - - - - - id: noteMeta - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/noteMeta - - Method=GET - filters: - - ValidateNoteKey - - id: getNote - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}} - - Method=GET - filters: - - ValidateNoteKey - - id: saveNote - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}} - - Method=POST - filters: - - ValidateNoteKey - - id: deleteNote - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/delete - - Method=POST - filters: - - ValidateNoteKey - - id: secretKey - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}/secretKey - - Method=POST - filters: - - ValidateNoteKey - - id: getNoteTxt - uri: lb://noteCommonService - order: -1 - predicates: - - Path=/note/{key:[abcdefhikmnopqstuvwxyz23456789]{16}}.txt - - Method=GET - filters: - - ValidateNoteKey - - - - -management: -# server: -# address: 127.0.0.1 -# port: 19000 - endpoint: - shutdown: - enabled: true - health: - enabled: true - show-details: always - endpoints: - web: - base-path: /f2w8u47ie56edc93/actuator - exposure: - include: shutdown,health - -logging: - level: - org.springframework.cloud.gateway: info - org.springframework.cloud.loadbalancer: info - org.springframework.web.reactive: info \ No newline at end of file diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..32572bb --- /dev/null +++ b/src/main/resources/bootstrap.yml @@ -0,0 +1,11 @@ +spring: + application: + name: flagnote-gateway + cloud: + config: + name: flagnote-gateway + profile: prd + uri: http://flagnote-config-01:8080/flagnote-config,http://flagnote-config-02:8080/flagnote-config + config: + import: optional:configserver:http://flagnote-config-01:8080/,optional:configserver:http://flagnote-config-02:8080/ +