The relevant code, see my open source project:
https://github.com/qianxingchuan/doraemon
Brief introduction
2017, I made a rookie in the logistics department of the cloud gateway called Asgard, when in order to achieve fast, fit only the Alibaba technology stack system, such as part of the authentication of the account directly to system access code rookie curing the gateway; another example call service part, directly to the cured generalization code calls the gateway HSF. These curing the code the way for Asgard scalability and flexibility have caused immeasurable limit.
After the departure from the rookie, in May 2019, in vivo do about cloud storage-related projects, particularly vivo infrastructure is not perfect, so there is a lot of duplication of work, such as almost every web application will be written exactly the same set of authentication app , web authentication, and configuration of common cors. This is my very unhappy, so I decided to re-write it again to Asgard in vivo, this rewrite, will improve the logistics rookie period before the cloud is not the time to do some things, such as highly customizable for each call stage, another example gateway must be support responsive, fully asynchronous, and support websocket and so on.
If it wants to achieve highly customized, then we need to have a plugin framework for handling highly pluggable, osgi too heavy, I do not want our application has too many dependencies and a published specification; ants gold dress set of open source sofa -ark, but also to meet my request, but for me, that was lightweight enough, in fact, as long as I can be independent of each plugin can be inside the gateway application, shown in Figure 1:
This article focuses on me based on Java class loader isolation module implemented a lightweight frame: Doraemon.
In the same JVM inside, our application can call any of a bundle of export out of the example, bundle are not visible to each other.
Doraemon Quick
Based on different implementations of authentication interfaces
See doraemon-sample sample project
The main project:
the Sample-auth-the Facade: authentication interface definitions
sample-auth-bundle1: 1 to achieve authentication interface-based
sample-auth-bundle2: realization of 2-based authentication interface
sample-auth-project: running bundle1 and bundle2 the main program
bundle of realization
- It can be based doraemon-project-archetype to build your code skeleton
-
Generated doraemon-bundle directory structure shown in Figure 2
The key-dependent bundle pom.xml follows:
...
<dependencies>
<!--业务的基本依赖 -->
<dependency>
<groupId>io.github.qianxingchuan.framework</groupId>
<artifactId>sample-auth-facade</artifactId>
</dependency>
<!--每个bundle的依赖,每个bundle 必须要有一个 io.github.qianxingchuan.framework.doraemon.BundleService实例 -->
<dependency>
<groupId>io.github.qianxingchuan.framework</groupId>
<artifactId>doraemon-facade</artifactId>
<version>0.1-RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
</dependencies>
...
</project>
Implemented inside the bundle, the frame is not limited, because doraemon running time of each bundle are isolated from each other, but each bundle must have a class to implement io.github.qianxingchuan.framework.doraemon.BundleService, and configured to bundle .properties
bundle.properties configuration is as follows:
init-class=io.github.qianxingchuan.doraemon.sample.auth.run.SampleBundleRun
skip-class=io.github.qianxingchuan.doraemon.sample.facade.AuthFacade
init-class, which means that the bundle is automatically performed inside the doIt initialization
skip-class does not mean that the class is loaded by the class loader bundle
So according to our representation of Figure 1, this configuration is to be loaded by bundle1 SampleBundleRun module class loader, AuthFacade by Application where the class loader to load.
After all code written by mvn clean compile package, .zip to generate a bundle of files.
bundle running
Reference sample-auth-project engineering