liteflow 更适应我们的项目使用了它
drools 感觉复杂度高些
官网地址:http://waitmoon.com/zh
视频地址:https://www.bilibili.com/video/BV1hg411A7jx
业务中是否写了大量的 if-else?是否受够了这些 if-else 还要经常变动? 业务中是否做了大量抽象,发现新的业务场景还是用不上? 是否各种调研规则引擎,发现不是太重就是接入或维护太麻烦,最后发现还是不如硬编码? 接下来给大家介绍一款全新的开源规则引擎——ice,以一个简单的例子,从最底层的编排思想,阐述 ice 与其他规则引擎的不同;讲述 ice 是如何使用全新的设计思想,契合解耦和复用的属性,还你最大的编排自由度。
http://waitmoon.com/zh/guide/getting-started.html
https://gitee.com/waitmoon/ice/blob/1.2.0/ice-server/src/main/resources/sql/ice.sql
CREATE DATABASE IF NOT EXISTS ice CHARACTER SET utf8mb4;
USE ice;
-- ----------------------------
-- Table structure for ice_app
-- ----------------------------
CREATE TABLE IF NOT EXISTS `ice_app` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(200) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'application name',
`info` VARCHAR(500) COLLATE utf8mb4_bin DEFAULT '',
`status` TINYINT(1) NOT NULL DEFAULT '1',
`create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Table structure for ice_base
-- ----------------------------
CREATE TABLE IF NOT EXISTS `ice_base` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(200) COLLATE utf8mb4_bin DEFAULT NULL,
`app` INT(11) NOT NULL COMMENT 'remote application id',
`scenes` VARCHAR(1000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'scenes(mutli scene split with ,)',
`status` TINYINT(11) NOT NULL DEFAULT '1' COMMENT '1 online 0 offline',
`conf_id` BIGINT(20) DEFAULT NULL,
`time_type` TINYINT(11) DEFAULT '1' COMMENT 'see TimeTypeEnum',
`start` DATETIME(3) DEFAULT NULL,
`end` DATETIME(3) DEFAULT NULL,
`debug` TINYINT(4) NOT NULL DEFAULT '1',
`priority` BIGINT(20) DEFAULT '1',
`create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `update_index` (`update_at`) USING BTREE
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Table structure for ice_conf
-- ----------------------------
CREATE TABLE IF NOT EXISTS `ice_conf` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`app` INT(11) NOT NULL COMMENT 'remote application id',
`name` VARCHAR(50) COLLATE utf8mb4_bin DEFAULT NULL,
`son_ids` VARCHAR(1000) COLLATE utf8mb4_bin DEFAULT NULL,
`type` TINYINT(4) NOT NULL DEFAULT '6' COMMENT 'see NodeTypeEnum',
`status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '1 online 0 offline',
`inverse` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'make true->false false->true',
`conf_name` VARCHAR(1000) COLLATE utf8mb4_bin DEFAULT '' COMMENT 'leaf node class name',
`conf_field` VARCHAR(5000) COLLATE utf8mb4_bin DEFAULT '' COMMENT 'leaf node json config',
`forward_id` BIGINT(20) DEFAULT NULL,
`time_type` TINYINT(11) NOT NULL DEFAULT '1' COMMENT 'see TimeTypeEnum',
`start` DATETIME(3) DEFAULT NULL,
`end` DATETIME(3) DEFAULT NULL,
`debug` TINYINT(4) NOT NULL DEFAULT '1',
`error_state` TINYINT(4) DEFAULT NULL COMMENT 'NULL/3-SHUTDOWN, 0-CONTINUE_FALSE, 1-CONTINUE_TRUE, 2-CONTINUE_NONE',
`create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `update_index` (`update_at`) USING BTREE
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Table structure for ice_conf_update
-- ----------------------------
CREATE TABLE IF NOT EXISTS `ice_conf_update` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`app` INT(11) NOT NULL COMMENT 'remote application id',
`ice_id` BIGINT(20) NOT NULL,
`conf_id` BIGINT(20) NOT NULL,
`name` VARCHAR(50) COLLATE utf8mb4_bin DEFAULT NULL,
`son_ids` VARCHAR(1000) COLLATE utf8mb4_bin DEFAULT NULL,
`type` TINYINT(4) NOT NULL DEFAULT '6' COMMENT 'see NodeTypeEnum',
`status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '1 online 0 offline',
`inverse` TINYINT(4) NOT NULL DEFAULT '0' COMMENT 'make true->false false->true',
`conf_name` VARCHAR(1000) COLLATE utf8mb4_bin DEFAULT '' COMMENT 'leaf node class name',
`conf_field` VARCHAR(5000) COLLATE utf8mb4_bin DEFAULT '' COMMENT 'leaf node json config',
`forward_id` BIGINT(20) DEFAULT NULL,
`time_type` TINYINT(11) NOT NULL DEFAULT '1' COMMENT 'see TimeTypeEnum',
`start` DATETIME(3) DEFAULT NULL,
`end` DATETIME(3) DEFAULT NULL,
`debug` TINYINT(4) NOT NULL DEFAULT '1',
`error_state` TINYINT(4) DEFAULT NULL COMMENT 'NULL/3-SHUTDOWN, 0-CONTINUE_FALSE, 1-CONTINUE_TRUE, 2-CONTINUE_NONE',
`create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`),
KEY `update_index` (`update_at`) USING BTREE
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Table structure for ice_push_history
-- ----------------------------
CREATE TABLE IF NOT EXISTS `ice_push_history` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`app` INT(11) NOT NULL,
`ice_id` BIGINT(20) DEFAULT NULL,
`reason` VARCHAR(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`push_data` LONGTEXT COLLATE utf8mb4_unicode_ci,
`operator` VARCHAR(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- v1.2.0
-- table ice_conf add column error_state if not exist
-- ----------------------------
SET @preparedStatement = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE
table_name = 'ice_conf'
AND table_schema = DATABASE()
AND column_name = "error_state"
) > 0,
"SELECT 1",
"ALTER TABLE ice_conf ADD error_state tinyint(4) DEFAULT NULL COMMENT 'NULL/3-SHUTDOWN, 0-CONTINUE_FALSE, 1-CONTINUE_TRUE, 2-CONTINUE_NONE';"
));
PREPARE iceConfAlterIfNotExists FROM @preparedStatement;
EXECUTE iceConfAlterIfNotExists;
DEALLOCATE PREPARE iceConfAlterIfNotExists;
-- ----------------------------
-- v1.2.0
-- table ice_conf_update add column error_state if not exist
-- ----------------------------
SET @preparedStatement = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE
table_name = 'ice_conf_update'
AND table_schema = DATABASE()
AND column_name = "error_state"
) > 0,
"SELECT 1",
"ALTER TABLE ice_conf_update ADD error_state tinyint(4) DEFAULT NULL COMMENT 'NULL/3-SHUTDOWN, 0-CONTINUE_FALSE, 1-CONTINUE_TRUE, 2-CONTINUE_NONE';"
));
PREPARE iceConfUpdateAlterIfNotExists FROM @preparedStatement;
EXECUTE iceConfUpdateAlterIfNotExists;
DEALLOCATE PREPARE iceConfUpdateAlterIfNotExists;
http://waitmoon.com/downloads/
[root@localhost ~]# cd /opt/
[root@localhost opt]# mkdir ice
# 创建目录
[root@localhost opt]# cd ice
# 下载安装包
[root@localhost ice]# wget http://waitmoon.com/downloads/ice-server-1.2.0.tar.gz
# 解压
[root@localhost ice]# tar -xzvf ice-server-*.tar.gz
ice-server-1.2.0/
ice-server-1.2.0/ice-server.jar
ice-server-1.2.0/logs/
ice-server-1.2.0/logs/ice-server.log
ice-server-1.2.0/application-prod.yml
ice-server-1.2.0/ice.sh
# 编辑配置文件,修改数据库配置
[root@localhost ice]# vi ice-server-1.2.0/application-prod.yml
修改配置(application-prod.yml)
server:
port: 8121 #端口
spring:
datasource: #数据库配置
url: jdbc:mysql://127.0.0.1:3306/ice?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useSSL=false
username: username
password: password
initialization-mode: always
ice:
port: 18121 #与客户端通信端口
# ha: #高可用配置,当前默认支持zookeeper
# address: localhost:2181,localhost:2182,localhost:2183
pool: #线程池配置(用于更新client)
core-size: 4
max-size: 4
keep-alive-seconds: 60
queue-capacity: 60000
启动 sh ice.sh start
停止 sh ice.sh stop
重启 sh ice.sh restart
POM
<dependency>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-client-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
<!--高可用模式-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>5.2.1</version>
</dependency>
application.yml
server:
port: 8082
ice: #ice client配置
app: 1 #与后台配置app对应
# server: zookeeper:localhost:2181,localhost:2182,localhost:2183 #server高可用配置
server: 172.16.3.64:18121 #server 地址(serverHost:serverPort) 服务中配置的端口
scan: com.ice.test #用于扫描叶子节点,多个包用','分隔(默认扫描全部,扫描全部会拖慢应用启动速度)
pool: #线程池配置(用于并发关系节点)
parallelism: -1 #默认-1,≤0表示采用默认配置
当 recharge 发生的时候触发
文档:http://waitmoon.com/zh/guide/#举例
视频:https://www.bilibili.com/video/BV1Q34y1R7KF