Skip to content

Commit

Permalink
deploy v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongFuCheng3y committed May 4, 2023
1 parent d65cf65 commit 99a60e2
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 66 deletions.
117 changes: 71 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,116 +18,141 @@
<a href="#项目交流"><img src="https://img.shields.io/badge/Nacos-2.1.0-red.svg" alt="ORM框架"></a>
</p>

### hades 介绍
## 一、hades 介绍

项目背景:业务开发逻辑变更频繁,一点小的修改都要发布系统,灵活度不够。对于一些**非核心流程又频繁改动**的部分是否可以用动态脚本替代
项目背景:业务开发逻辑变更频繁,一点小的修改都要发布系统,灵活度不够。对于一些**非核心流程又频繁改动**的部分是否可以用**动态脚本**替代

核心功能:**Java应用无须发布上下线,即可动态变更业务逻辑**
核心功能:**Java应用无须发布上下线,动态变更业务逻辑,对象实例均交由Spring管理**


### hades 技术原理

核心技术:Groovy+分布式配置中心(`apollo`/`nacos`)
## 二、hades 使用手册

![](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9dfc77529693487fad9dba07c6d09480~tplv-k3u1fbpfcp-watermark.image?)
### 2.1 引入maven依赖

技术原理:将`Groovy`脚本写在配置中心里,借助分布式配置中心监听配置功能,客户端能实时发现`Groovy`脚本变更。`hades`规则引擎将`Groovy`脚本解析后,放入`Spring IOC`容器中供客户端使用。


### hades 使用手册

1、引入maven依赖:
```xml

<!--如果你用apollo,则引入该dependency-->
<!--如果你用apollo,则引入该dependency,建议用最新的版本-->
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-apollo-starter</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>

<!--如果你用nacos,则引入该dependency-->
<!--如果你用nacos,则引入该dependency,建议用最新的版本-->
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-nacos-starter</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>

```

2、在接入`hades`规则引擎的项目配置文件中(如:`application.properties`)填写主配置的文件名
### 2.2 配置信息

在接入`hades`的项目配置文件中(如:`application.properties`)填写`hades`相关的配置信息

`nacos`分布式配置中心示例:

```properties

nacos.config.server-addr=austin-nacos:8848
nacos.config.username=nacos
nacos.config.password=nacos
nacos.config.namespace=9537c674-f3a6-4203-b286-ef0c36bfacb2
nacos.config.namespace=hades
nacos.config.enabled=true

# heades param you should write
hades.main.config.enabled=true
hades.main.config.file-name=hades
hades.main.config.group-name=hades
# hades param you should write
hades.enabled=true
hades.config-name=hades
```

`apollo`分布式配置中心示例:

```properties

app.id=austin
app.id=hades
apollo.bootstrap.enabled=true
apollo.meta=austin-apollo

# heades param you should write
hades.main.config.enabled=true
hades.main.config.file-name=hades
# hades param you should write
hades.enabled=true
hades.config-name=hades
```
### 2.3 部署后端和前端(可选)

目前后端部署仅支持使用`nacos`的小伙伴,`hades`有对应配置页面,将`hades`的前端和后端部署起来会方便使用些。


后端是`SpringBoot`应用,入口:`com.java3y.hades.HadesApplication`,前端是`amis`低代码平台,点击前端[Git仓库](https://gitee.com/zhongfucheng/hades-admin)进行部署。

后端的模块是在`hades-web`,对应的配置文件在`application.properties`,按自身情况自行修改:

```properties
# hades param you should write
hades.enabled=true
hades.config-name=hades

# nacos
nacos.config.enabled=true
nacos.config.server-addr=austin-nacos:8848
nacos.config.username=nacos
nacos.config.password=nacos
nacos.config.namespace=hades

```

3、在对应的分布式配置中心创建`hades`主配置,配置内容如下:
1、可选择直接添加Java代码,注意不要用**lombok****lambda**,groovy是不认的。
![](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e25df3922a7f48d7aff01d41671815fa~tplv-k3u1fbpfcp-watermark.image?)

2、如果是轻量级的逻辑,也可以直接在界面上配置逻辑,比如对字符串和数值的判断。当提交了之后,会根据条件自动生成对应`Java`代码,注册到`iOC`容器中

![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0129320edd2c4e4aa1ae73774ce807d7~tplv-k3u1fbpfcp-watermark.image?)

3、添加规则完后,能在规则列表中看到对应内容,并将其**脚本注册**`Spring iOC`容器中,供客户端使用

![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/3e5ce613284a4c699ed7cfab085bc285~tplv-k3u1fbpfcp-watermark.image?)

(注:`hades`所有的配置内容**在分布式配置中心**默认均为`txt`格式)
### 2.4 不部署后端和前端

完全可以只通过分布式配置中心的后台,**手动去创建配置**,来实现效果。步骤如下:

1、在对应的分布式配置中心创建`hades`主配置(配置名是`hades.config-name`的值),配置内容如下:

```json
{
"instanceNames": [
"TencentSmsService"
"com.java3y.hades.domain.HadesParam"
],
"updateTime": "2023年3月20日10:26:0131"
}
```
说明`hades`主要是监听以上配置的变更,当新增或修改了`Groovy`脚本时,需要**手动**更新该配置。
`hades`所有的配置内容**在分布式配置中心**默认均为`txt`格式。`hades`会监听以上配置的变更,当新增或修改了`Groovy`脚本时,需要**手动**更新该配置。

4、新建`Groovy`脚本,`apollo`需要跟**主配置**在同`appId`下,`nacos`在同`namespace`下。
2、新建`Groovy`脚本,`apollo`需要跟**主配置**在同`appId`下,`nacos`在同`namespace`下。`Groovy`脚本跟`Java`代码**99%相同**(不写`lambda``lambda`即可)

**注:`Groovy`脚本跟`Java`代码99%相同(特别要注意`lambda`语法和`lombok`的问题,建议不写`lambda`**
![](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c5e929b392304c1ba78535df5f932568~tplv-k3u1fbpfcp-watermark.image?)

5、客户端使用`HadesClient`获取对象或执行方法

```java

### 2.5使用客户端

客户端使用`HadesClient`获取对象或执行方法

```java
@RequestMapping("/test")
private void test() {
// 获取脚本对象,用接口接收
SendSmsService sendSmsService = hadesClient.getInterfaceByName("TencentSmsService");
SendSmsService sendSmsService = hadesClient.getInterfaceByName("com.java3y.hades.example.apollo.demo.TencentSmsService");
sendSmsService.send();

// 获取GroovyObject对象
GroovyObject groovyObject = hadesClient.getGroovyObjectByName("TencentSmsService");
GroovyObject groovyObject = hadesClient.getGroovyObjectByName("com.java3y.hades.example.apollo.demo.TencentSmsService");
groovyObject.invokeMethod("send", null);
log.info("groovy object:{}", groovyObject);

// 直接执行脚本对应的方法,得到返回值
Object execute = hadesClient.execute("TencentSmsService", "send", null);
Object execute = hadesClient.execute("com.java3y.hades.example.apollo.demo.TencentSmsService", "send", null);
System.out.println("result" + execute);
}

```

### hades 示例

`hades-apollo-example``hades-nacos-example`可用于调试



```
2 changes: 1 addition & 1 deletion hades-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hades-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion hades-example/hades-apollo-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades-example</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hades-apollo-example</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app.id=austin
apollo.bootstrap.enabled=true
# heades param you should write
# hades param you should write
hades.enabled=true
hades.config-name=hades
2 changes: 1 addition & 1 deletion hades-example/hades-nacos-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades-example</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hades-nacos-example</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
server.port=7890

nacos.config.server-addr=austin-nacos:8848
nacos.config.username=nacos
nacos.config.password=nacos
nacos.config.namespace=hades
nacos.config.enabled=true
# heades param you should write
# hades param you should write
hades.enabled=true
hades.config-name=hades
4 changes: 2 additions & 2 deletions hades-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -25,7 +25,7 @@
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
4 changes: 2 additions & 2 deletions hades-starter/hades-apollo-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades-starter</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
Expand Down
4 changes: 2 additions & 2 deletions hades-starter/hades-nacos-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades-starter</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
Expand Down
2 changes: 1 addition & 1 deletion hades-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<packaging>pom</packaging>
<modules>
Expand Down
4 changes: 2 additions & 2 deletions hades-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hades</artifactId>
<groupId>io.github.ZhongFuCheng3y</groupId>
<version>1.0.3</version>
<version>1.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades-core</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
5 changes: 0 additions & 5 deletions hades-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ nacos.config.username=nacos
nacos.config.password=nacos
nacos.config.namespace=hades

# apollo
app.id=austin
apollo.bootstrap.enabled=false
apollo.portal.address=austin-apollo-admin:8070
apollo.bootstrap.namespaces=hades


2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.ZhongFuCheng3y</groupId>
<artifactId>hades</artifactId>
<packaging>pom</packaging>
<version>1.0.3</version>
<version>1.0.4</version>

<modules>
<module>hades-core</module>
Expand Down

0 comments on commit 99a60e2

Please sign in to comment.