Skip to content

Commit

Permalink
perf($api-gateway): DDD modularized microservice
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Feb 4, 2022
1 parent 91c0fe5 commit ee45dab
Show file tree
Hide file tree
Showing 57 changed files with 464 additions and 311 deletions.
23 changes: 23 additions & 0 deletions api-gateway/api-gateway-biz/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Sub-module Basics -->
<artifactId>api-gateway-biz</artifactId>
<name>Muscle and Fitness Server :: API Gateway - Biz</name>
<description>API Gateway for Muscle and Fitness microservices.</description>
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.8-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway-domain</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jmsoftware.maf.apigateway.security.impl;

import cn.hutool.core.util.StrUtil;
import com.jmsoftware.maf.apigateway.remoteapi.AuthCenterRemoteApi;
import com.jmsoftware.maf.apigateway.remote.AuthCenterRemoteApi;
import com.jmsoftware.maf.common.domain.authcenter.security.UserPrincipal;
import com.jmsoftware.maf.common.exception.BizException;
import com.jmsoftware.maf.common.exception.SecurityException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jmsoftware.maf.apigateway.security.impl;

import cn.hutool.core.util.StrUtil;
import com.jmsoftware.maf.apigateway.remoteapi.AuthCenterRemoteApi;
import com.jmsoftware.maf.apigateway.remote.AuthCenterRemoteApi;
import com.jmsoftware.maf.common.domain.authcenter.security.UserPrincipal;
import com.jmsoftware.maf.common.exception.SecurityException;
import com.jmsoftware.maf.reactivespringcloudstarter.property.JwtConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.jmsoftware.maf.apigateway.remoteapi.AuthCenterRemoteApi;
import com.jmsoftware.maf.apigateway.remote.AuthCenterRemoteApi;
import com.jmsoftware.maf.common.constant.MafHttpHeader;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway.security;
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway;
184 changes: 184 additions & 0 deletions api-gateway/api-gateway-bootstrap/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Sub-module Basics -->
<artifactId>api-gateway-bootstrap</artifactId>
<name>Muscle and Fitness Server :: API Gateway - Bootstrap</name>
<description>API Gateway for Muscle and Fitness microservices.</description>
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.8-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Build Settings -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<phase>compile</phase>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<configuration>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<targetJdk>${java.version}</targetJdk>
<printFailingErrors>true</printFailingErrors>
<rulesets>
<ruleset>rulesets/java/ali-comment.xml</ruleset>
<ruleset>rulesets/java/ali-concurrent.xml</ruleset>
<ruleset>rulesets/java/ali-constant.xml</ruleset>
<ruleset>rulesets/java/ali-exception.xml</ruleset>
<ruleset>rulesets/java/ali-flowcontrol.xml</ruleset>
<ruleset>rulesets/java/ali-naming.xml</ruleset>
<ruleset>rulesets/java/ali-oop.xml</ruleset>
<ruleset>rulesets/java/ali-orm.xml</ruleset>
<ruleset>rulesets/java/ali-other.xml</ruleset>
<ruleset>rulesets/java/ali-set.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.alibaba.p3c</groupId>
<artifactId>p3c-pmd</artifactId>
<version>${p3c-pmd.version}</version>
</dependency>
</dependencies>
</plugin>

<!-- https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md -->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-spring-boot-extension-maven</artifactId>
<version>${jib-spring-boot-extension-maven.version}</version>
</dependency>
</dependencies>
<executions>
<!-- Bind `jib:dockerBuild` to a Maven lifecycle `verify`. Jib will build your image directly to a Docker daemon.
<execution>
<id>buildDockerImagePhase</id>
<phase>verify</phase>
<goals>
<goal>dockerBuild</goal>
</goals>
</execution> -->
<!-- Bind `jib:build` to a Maven lifecycle `install`. Jib will build and push image to image registry. -->
<execution>
<id>buildAndPushDockerImagePhase</id>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<from>
<!-- Don't use alpine or slim version, https://hub.docker.com/r/adoptopenjdk/openjdk11/tags?page=1&ordering=last_updated&name=jre-11 -->
<image>adoptopenjdk/openjdk11:${adoptopenjdk11.tag}</image>
</from>
<to>
<image>docker.io/ijohnnymiller/${project.baseArtifactId}.${project.parent.artifactId}</image>
<tags>
<tag>${git.commit.id.abbrev}-${project.version}</tag>
</tags>
</to>
<container>
<!-- The root directory on the container where the app's contents are placed. -->
<appRoot>/${project.parent.artifactId}</appRoot>
<jvmFlags>
<jvmFlag>-Dfile.encoding=${project.build.sourceEncoding}</jvmFlag>
</jvmFlags>
<ports>
<port>${api-gateway.port}</port>
</ports>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
<pluginExtensions>
<pluginExtension>
<implementation>
com.google.cloud.tools.jib.maven.extension.springboot.JibSpringBootExtension
</implementation>
<properties>
<excludeDevtools>true</excludeDevtools>
</properties>
</pluginExtension>
</pluginExtensions>
</configuration>
</plugin>

<!-- https://github.com/git-commit-id/git-commit-id-maven-plugin -->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>get-the-git-info</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>

<dependencies>
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway-web</artifactId>
</dependency>
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway-message</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@Slf4j
@EnableDiscoveryClient
@SpringBootApplication
@SuppressWarnings("scwjava_Createprivateconstructorforutilityclassallfieldsmethodsarestatic")
public class ApiGatewayApplication {
public static void main(String[] args) {
val stopWatch = new StopWatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@ server:
context-path:

spring:
application:
name: @project.parent.artifactId@
profiles:
active: @environment@
mvc:
throw-exception-if-no-handler-found: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: Asia/Hong_Kong
config:
import: consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}
cloud:
# https://docs.spring.io/spring-cloud-consul/docs/current/reference/html/index.html#spring-cloud-consul-config
consul:
host: "should-be-passed-by-java-opts"
port: 8500
config:
# `default-context` should not be modified, keeps "application" for common configuration.
# Properties in the config/application folder are applicable to all applications using consul for configuration.
profile-separator: "::"
format: YAML
data-key: "data"
watch:
enabled: true
delay: 1000
prefixes:
- config
discovery:
register: true
instance-id: ${spring.application.name}-${spring.cloud.client.hostname}-${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
Expand All @@ -35,30 +48,9 @@ spring:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
redis:
database: 0
timeout: 10000ms
client-type: LETTUCE
lettuce:
pool:
max-active: 20
max-idle: 10
max-wait: -1ms
min-idle: 0

management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS

logging:
config: classpath:logback-configuration/logback-${spring.profiles.active}.xml
level:
org.springframework.cloud.client.loadbalancer.reactive: DEBUG

maf:
project-properties:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
**/
@Slf4j
@SpringBootTest
public class AuthorizationTests {
class AuthorizationTests {
@Test
void antPathMatcherTests() {
val antPathMatcher = new AntPathMatcher();
Expand Down
23 changes: 23 additions & 0 deletions api-gateway/api-gateway-domain/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Sub-module Basics -->
<artifactId>api-gateway-domain</artifactId>
<name>Muscle and Fitness Server :: API Gateway - Domain</name>
<description>API Gateway for Muscle and Fitness microservices.</description>
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.8-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway-infra</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway;
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway;
16 changes: 16 additions & 0 deletions api-gateway/api-gateway-infra/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Sub-module Basics -->
<artifactId>api-gateway-infra</artifactId>
<name>Muscle and Fitness Server :: API Gateway - Infra</name>
<description>API Gateway for Muscle and Fitness microservices.</description>
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.8-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.apigateway;
Loading

0 comments on commit ee45dab

Please sign in to comment.