fast-drools-spring-boot-starter
integrates Drools with Springboot providing a more efficient, sophisticated model for rule configuration and management. It is capable of updating rules dynamically with regards to hot deployment.
Feel free to ask me any questions with the contacts below.
1)Demo?
2)Why I can't dynamically update rules in development environment?
3)...
1)Inject the following dependency in pom.xml
(update 2021/01/20):
<dependency>
<groupId>com.github.hongwen1993</groupId>
<artifactId>fast-drools-spring-boot-starter</artifactId>
<version>8.0.9</version>
</dependency>
2)Designate path to drools rule file in the configruation file
# (necessary) specify a rule file folder that will automatically scan all rule files, include decision tables, and CSV files,
# also support classpath resource path, example:classpath:drools/**/*.drl
# win system use \\, example C:\\DRL\\
# linux system use /, example /var/config/
spring.drools.path = C:\\DRL\\
# set up mode with options "stream" or "cloud" (default = stream)
spring.drools.mode = stream
# close drl file auto update, on or off (default = on)
spring.drools.auto-update = on
# regulates update cycle, unit is seconds (default = 30)
spring.drools.update = 10
# monitoring rules, on or off (default = on)
spring.drools.listener = on
# open drl syntax checker, on or off (default = off)
spring.drools.verify = off
# default drl file charset(default utf-8)
spring.drools.charset = GBK
3)Introduce KieTemplate with annotation
@Autowired
private KieTemplate kieTemplate;
4)Session can be acquired with getKieSession(). Supporting multiple rule files at the same time as well as decisions tables.
KieSession kieSession = kieTemplate.getKieSession("rule1.drl", "rule2.drl");
......
5)Results
2020-09-10 16:51:08.344 DEBUG ===>>开始更新规则文件
2020-09-10 16:51:09.730 DEBUG ===>>插入对象:[fact 0:1:1571707504:1072693248:1:DEFAULT:NON_TRAIT:java.lang.Double:1.0];操作规则:null
2020-09-10 16:51:09.748 DEBUG ===>>匹配的规则:[Rule name=规则1-1, agendaGroup=MAIN, salience=0, no-loop=false]
2020-09-10 16:51:09.761 DEBUG ===>>开始执行Java代码块,匹配规则:[Rule name=规则1-1, agendaGroup=MAIN, salience=0, no-loop=false],评估对象:[[fact 0:1:1571707504:1072693248:1:DEFAULT:NON_TRAIT:java.lang.Double:1.0]]
.... 执行过程忽略 ....
2020-09-10 16:51:09.765 DEBUG ===>>结束执行Java代码块,匹配规则:[Rule name=规则1-1, agendaGroup=MAIN, salience=0, no-loop=false],评估对象:[[fact 0:1:1571707504:1072693248:1:DEFAULT:NON_TRAIT:java.lang.Double:1.0]]
(KieTemplate 下封装了许多 Drools 的功能,许多便捷的 API 等你来发现!)
If you are using fast-drools and think that it helps you or want do some contributions to it, please call me to let us know just for promotional purposes only.