Preface
In open source China, I wonder if you have noticed a Java open source organization-Dromara?
This organization was founded by the author of Apache ShenYu (formerly Soul Gateway) and a Java open source organization participated by many Java open source authors.
In the open source Chinese community, many Java open source authors are fighting independently and operating projects independently. The Domara organization was born to unite the power of Java open source, build a community, share resources, and jointly promote the development of China's Java open source business.
Currently, the Dromara community has 9 GVP projects and some projects with a high number of Stars. These open source project communities are very active, and each is a boutique open source work that can improve work efficiency. Let's take a look at the 4 open source projects in the Dromara organization. They are all very practical tools, using them well will greatly improve your production efficiency!
Sa-Token
first thing I want to introduce is Sa-Token, which is probably the most versatile lightweight Java authorization framework in history.
simple to use, rich in features, powerful functions, what reason do you have to refuse?
Official website: http://sa-token.dev33.cn/
Gitee hosting warehouse: https://gitee.com/dromara/sa-token
Github hosting warehouse: https://github.com/dromara/Sa-Token
Sa-Token is a lightweight Java permissions authentication framework, mainly to solve: login authentication
, certification authority
, the Session Session
, single sign-
, OAuth2.0
, micro Service gateway authentication
And a series of permissions-related issues.
The API design of Sa-Token is very simple, how simple is it? Take login authentication as an example, you only need:
// 在登录时写入当前会话的账号id
StpUtil.login(10001);
// 然后在需要校验登录处调用以下方法:
// 如果当前会话未登录,这句代码会抛出 `NotLoginException` 异常
StpUtil.checkLogin();
So far, we have completed the login authentication with the help of Sa-Token!
Your little head may be full of question marks at this time, it's that simple? What about custom Realm? What about global filters? Do I need to write various configuration files?
That's right, in Sa-Token, login authentication is so simple, without any complicated pre-work, just a simple API call to complete the session login authentication!
When you are fed up with Shiro, SpringSecurity and other frameworks, you will understand how simple and elegant Sa-Token's API design is compared to these traditional old-fashioned frameworks!
Permission authentication example (only user:add
permission can enter the request)
@SaCheckPermission("user:add")
@RequestMapping("/user/insert")
public String insert(SysUser user) {
// ...
return "用户增加";
}
Kick an account offline (it will throw NotLoginException
exception when the other party accesses the system again)
// 使账号id为 10001 的会话强制注销登录
StpUtil.logoutByLoginId(10001);
In Sa-Token, most functions can be completed by one line of code
StpUtil.login(10001); // 标记当前会话登录的账号id
StpUtil.getLoginId(); // 获取当前会话登录的账号id
StpUtil.isLogin(); // 获取当前会话是否已经登录, 返回true或false
StpUtil.logout(); // 当前会话注销登录
StpUtil.logoutByLoginId(10001); // 让账号为10001的会话注销登录(踢人下线)
StpUtil.hasRole("super-admin"); // 查询当前账号是否含有指定角色标识, 返回true或false
StpUtil.hasPermission("user:add"); // 查询当前账号是否含有指定权限, 返回true或false
StpUtil.getSession(); // 获取当前账号id的Session
StpUtil.getSessionByLoginId(10001); // 获取账号id为10001的Session
StpUtil.getTokenValueByLoginId(10001); // 获取账号id为10001的token令牌值
StpUtil.login(10001, "PC"); // 指定设备标识登录,常用于“同端互斥登录”
StpUtil.logoutByLoginId(10001, "PC"); // 指定设备标识进行强制注销 (不同端不受影响)
StpUtil.openSafe(120); // 在当前会话开启二级认证,有效期为120秒
StpUtil.checkSafe(); // 校验当前会话是否处于二级认证有效期内,校验失败会抛出异常
StpUtil.switchTo(10044); // 将当前会话身份临时切换为其它账号
Even if you don't run the test, I believe you will be aware of the usage of most APIs.
For more information, please refer to: https://gitee.com/dromara/sa-token
Forest
A powerful Http client framework that greatly liberates your Http access work.
Http protocol complicated? That's because you haven't used Forest. Although there are many other excellent Http clients in the industry, if you miss the Forest, you will miss a large piece of elegant and beautiful forest.
Official website: http://forest.dtflyx.com
Gitee hosting warehouse: https://gitee.com/dromara/forest
Github hosting warehouse: https://github.com/dromara/forest
Forest is an open source Java HTTP client framework for accessing RESTful interfaces of third-party services.
It can bind HTTP request parameters to a Java interface, and then calling the Java interface is equivalent to sending an HTTP request. Everything is interface-oriented.
Many companies need to call many third-party HTTP interfaces in the Java backend, such as WeChat Pay, Youmeng and other third-party platforms.
There are many internal services in the company that are written in the world's best language, and the interface can only be called through the HTTP interface. As a result, over time, there are many various HTTP calling interfaces in the Java code, and the calling methods are not uniform. Some are written by HttpClient, written by OkHttp, and have their own packaging. They are packaged by different people within the company. There are two or three types of HTTP tools.
Moreover, the URL is basically hard-coded in the code, which is difficult to maintain. Different interfaces have different parameter transmission methods, such as GET, POST, JSON transmission, and XML transmission. When an interface needs to be modified, it will take half a day to find out where the code is.
And Forest can help me decouple the HTTP code and business code well, so that the requester does not need to care about the details of HTTP.
Automatic splicing of various HTTP parameters
Parameters including URL, Header, Body, etc. can all be declared by Java annotations.
Here is a chestnut of the Gaode map to see how Forest gracefully declares the HTTP request interface:
/**
* 高德地图服务客户端接口
*/
@BaseRequest(baseURL = "http://ditu.amap.com")
public interface Amap {
/**
* 根据经纬度获取详细地址
* @param longitude 经度
* @param latitude 纬度
* @return 详细地址信息
*/
@Get("/service/regeo")
Map getLocation(@Query("longitude") String longitude, @Query("latitude") String latitude);
}
... ...
Amap amp = Forest.client(Amap.class);
// 发送请求查询经纬度
Map locationInfo = amp.getLocation("32.1242832", "56.3290434");
Automatic JSON and XML conversion
In fact, when we deal with HTTP, in addition to wasting various request parameters, most of the time is spent serializing and deserializing data in various formats, such as JSON and XML.
Before using HttpClient, these repetitive mechanical tasks had to be done by yourself, which was very troublesome.
It is much more convenient to use Forest. For example, if you want to POST a JSON object, just hang @JSONBody directly. It's so refreshing.
// 直接将 MyUserInfo 转换成 JSON
// 将服务端响应返回的 JSON 数据转换成 Result<Boolean> 类对象
@Post("http://localhost:8080/user")
Result<Booelean> createUser(@JSONBody MyUserInfo user);
and Retrofit and Feign
I have used these two open source frameworks before, both of which are powerful, but each has its own advantages and disadvantages.
The main problem of Retrofit is that it is tied to OkHttp too deadly. Some functions are restricted by OkHttp. For example, I want to process Get requests and transmit Body data, which is a non-standard HTTP request that is difficult to do. Forest can switch OkHttp and OkHttp at will. HttpClient is used as the backend, which one needs to be used.
Retrofit annotations are not as rich as Forest. For example, if you want to implement an HTTP network proxy, you have to write your own code, and Forest provides @HTTPProxy annotations, just set it up and you're done.
If you want to extend the custom annotations are based on OkHttp interceptors, it is not particularly convenient, and the Forest interceptor is much more convenient than OkHttp. It provides onInvoke, beforeExecute, onSccuess, onError and other callback methods, which is equivalent to covering the birth, old, sick and dead of a request .
The problem with Feign is that it is too tightly tied to Spring, many functions need to be done by Spring, and Spring related packages are too heavy.
The core package of Forest basically covers all the functions and annotations required by HTTP, does not rely on Spring, is much lighter, but does not lose convenience.
For more information, please refer to: https://gitee.com/dromara/forest
LiteFlow
an ultra-lightweight, fast, stable, and orchestrable component-based process engine/rule engine.
an artifact of decoupling complex systems! If you are having a headache for designing a complex system, then LiteFlow is your best choice. The ultra-low learning cost and powerful orchestration function make your system more elegant!
Official website: https://yomahub.com/liteflow
Gitee hosting warehouse: https://gitee.com/dromara/liteFlow
Github hosting warehouse: https://github.com/dromara/liteflow
Liteflow was born to decouple complex logic. If you want to write or refactor complex business logic, liteflow is the most suitable. It is a lightweight, fast component-based process engine framework, component orchestration, to help decouple business code, so that every business fragment is a component.
Using Liteflow, you need to split the complex business logic into small components according to code fragments, and define a rule flow configuration. In this way, all components can be configured in accordance with your rules to carry out complex circulation. At the same time, Liteflow supports hot loading of rule files, and the modification takes effect immediately. And provide a variety of ways to extend the persistence rules.
With LiteFLow, the three core concepts are components, rules and context.
You need to define your component like this
//这里普通组件
@LiteflowComponent(id = "a", name = "组件A描述")
public class ACmp extends NodeComponent {
@Override
public void process() {
//do your business
}
}
//这是条件组件
@LiteflowComponent(id = "b", name = "组件B描述")
public class BCondCmp extends NodeCondComponent {
@Override
public String processCond() {
//do your business
return "e";
}
}
Then go to define your rules, LiteFlow supports xml, yml, json three formats, here is the xml format as an example
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<then value="a,b(c|d|e)"/> <!-- c为路由组件,用来路由到c,d,e -->
<then value="sub_chain"/> <!-- 子流程 -->
</chain>
<chain name="sub_chain">
<when value="f,g,h"/> <!-- when代表并行 -->
<then value="j,k" /> <!-- then代表串行 -->
</chain>
</flow>
In this way, your system will execute your business components in accordance with the way defined in the rule file. Is not it simple.
Where is the rule file defined? LiteFlow does not limit the source of your rule file. It can be a local file, a registry, or any database. LiteFlow provides a very free interface for you to expand, you can store it wherever you want. Change the rule file to refresh your rule flow in real time! If you want to build a highly flexible and scalable system, is LiteFlow very suitable?
LiteFlow develops and applies for a Slot for every request. You can understand it as a context. All components share this Slot. You can get any data by accessing Slot in any component, and you can also store any data. You can also extend Slot and customize the attributes of this slot.
@LiteflowComponent(id = "a", name = "组件A描述")
public class ACmp extends NodeComponent {
@Override
public void process() {
Slot slot = this.getSlot();
//通过对slot的getData,setData,或者存取你自己扩展的slot属性
}
}
It is precisely because of the existence of Slot that the differences between components are smoothed out, so that there is no strong dependency between each business component. This design allows your system to be highly liberalized, component reuse, and component replacement sequence can be easily realized!
LiteFlow also supports the access of two scripting languages, and currently supports Groovy and QLExpress two scripting languages. You can define the script in xml/yml/json, the following takes xml as an example:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="s1" name="普通脚本" type="script">
<![CDATA[
def a=3;
def b=2;
slot.setData("s1",a*b);
]]>
</node>
<node id="s2" name="条件脚本" type="cond_script">
<![CDATA[
count = slot.getData("count");
if(count > 100){
return "a";
}else{
return "b";
}
]]>
</node>
</nodes>
<chain name="chain1">
<then value="a,b,c,s1"/>
</chain>
<chain name="chain2">
<then value="d,s2(a|b)"/>
</chain>
</flow>
So where is the script of which language defined? The scripting function of LiteFlow is the realization of an SPI mechanism. Which script package you rely on will be executed in which script.
With the support of scripting language, can even business code be hot deployed? Does it smell?
The functions of LiteFlow are much more than these. If you want to know more, please go to the official website to check and understand. I believe LiteFlow will make you feel elegant and stunning.
For more information, please refer to: https://yomahub.com/liteflow
JPom
A simple and light low-invasive online construction, automatic deployment, daily operation and maintenance, project monitoring software
The gospel of DevOps for small and medium company teams! Lightweight and powerful, don't you try?
Official website: https://jpom.io/
Gitee hosting warehouse: https://gitee.com/dromara/Jpom
Github hosting warehouse: https://github.com/dromara/Jpom
Jpom is a simple and light low-invasive online construction, automatic deployment, daily operation and maintenance, project monitoring software
In small and medium-sized companies or teams, the common method for traditional project deployment and operation and maintenance processes is to log in to the server to upload new project packages, execute corresponding command management, and repeat the above steps if multiple projects are managed.
There are many DevOps software on the market, but these software are basically difficult to learn and rely heavily on. Jpom is a low intrusion
small and medium-sized companies or teams, and
is a lightweight DevOps software that relies on
main functions and characteristics of the project
- Create, modify, delete projects, Jar package management
- View console log, backup log, delete log, export log in real time
- Build a project online, publish a project with one click
- Multi-node management, multi-node automatic distribution
- Online SSH terminal with terminal log and disable command
- Real-time monitoring of abnormal project status and automatic alarm
- cpu, ram monitoring, export stack information, view project process port, server status monitoring
- Multi-user management, independent user project permissions (upload and delete permissions can be controlled), complete operation log
- System path whitelist mode to prevent users from mistakenly operating system files
- Online management of Nginx configuration files, ssl certificate files
One-click installation (Linux) (recommended)
plug-in side
If the server also needs to be managed, the plug-in also needs to be installed on the server
The installation path is located in the execution command directory (the data and log storage directory is located in the installation path by default, if you need to modify the reference configuration file:
extConfig.yml
)
yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Agent
备用地址
yum install -y wget && wget -O install.sh https://cdn.jsdelivr.net/gh/dromara/Jpom/docs/install.sh && bash install.sh Agent
支持自动安装jdk环境
yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Agent jdk
After successful startup, the port on the plug-in side is 2123
server
The installation path is located in the execution command directory (the data and log storage directories are located in the installation path by default, if you need to modify the reference configuration file:
extConfig.yml
)If you need to modify the data and log storage path, please refer to the
jpom.path
configuration properties in theextConfig.yml
yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Server
备用地址
yum install -y wget && wget -O install.sh https://cdn.jsdelivr.net/gh/dromara/Jpom/docs/install.sh && bash install.sh Server
支持自动安装jdk环境
yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Server jdk
支持自动安装jdk和maven环境
yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/install.sh && bash install.sh Server jdk+mvn
After the startup is successful, the port of the 2122
access the management page, such as http://localhost:2122/
Special reminder: When one-click installation, pay attention to the execution command can not be in the same directory, that is, Server and Agent can not be installed in the same directory
If you can’t access, check if the firewall
systemctl status firewalld
is turned on. If the status shows greenActive: active (running)
can temporarily turn off the firewallsystemctl stop firewalld
, and then restart the firewallfirewall-cmd --reload
(It is recommended to use it only in a test environment, and use it with caution in a production environment)
If you still cannot access after turning off the firewall, and you are using a cloud server, you also need to turn off the firewall in the cloud server management background
For more information, please refer to: https://gitee.com/dromara/Jpom
finally
The open source projects recommended above are only four of the Dromara Java community, and there are many more outstanding open source projects in the Dromara community. Every project is condensed with the hard work and dedication of every author day and night. They embrace the world with an open mind, and use the power of technology to contribute to China's open source business.
We strive to shine, in order to illuminate others, and to brighten ourselves.
At the same time, I also hope that more Java open source authors can join the Dromara community, gather the strength of our generation, gather the achievements of all the monarchs, overcome obstacles, and help each other.
Finally, when you see the children's shoes here, like them, share them, and watch them!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。