Osheep

时光不回头,当下最重要。

Business rules engine - Java

故事首先从数据库说起。产品经理(非技术人员)需要访问数据库做数据报表&聚合&分析等操作,只需掌握SQL即可,一般无需技术人员介入。
这背后的实现逻辑流程如下。

《Business rules engine - Java》

1506533851207.jpg

同理思考业务逻辑,是否能够做到:产品经理提出需求,产品经理实现需求,无需技术人员介入?答案可能是Business rules engine,(相似的历史进程)。

《Business rules engine - Java》

1506533890303.jpg

Business rules engine 介绍
https://en.wikipedia.org/wiki/Business_rules_engine
Java Rule Engine 介绍
https://www.ibm.com/developerworks/cn/java/j-java-rules/index.html
Java Specification Requests
https://zh.wikipedia.org/wiki/JCP
JSR-94
https://www.jcp.org/en/jsr/detail?id=94
Oracel JDK JSR-94 实现
http://www.oracle.com/technetwork/articles/java/javarule-139829.html
Open Source Rule Engines in Java
http://java-source.net/open-source/rule-engines

程序员的理想:不写业务需求代码

产品经理编辑Excel或txt文件,线上生产环境即生效,无需开发人员介入。

Java Rule Engine 厂商方案调研

OpenRules – Excel

http://openrules.com/
DecisionHello Excel Sample

MRules – XML

https://mrules.xyz/en/

<?xml version="1.0" encoding="UTF-8"?>
<rules implem="RULEEXECUTIONSET" name="Hello" contextFactory="CONTEXT:example.dzone.User">
    <executable implem="PRINTF" message="Hello {{first}} {{last}}, how are you today ?" first=":firstName" last=":lastName" /> 
</rules>

JRuleEngine – XML

http://jruleengine.sourceforge.net/

JLisa – Unknown

http://jlisa.sourceforge.net/

Drools – 网页在线编辑

https://www.drools.org/

  • Build Running
    《Business rules engine - Java》

    image
  • Data Modeller
    《Business rules engine - Java》

    image
  • Limited Decision Table
    《Business rules engine - Java》

    image
  • Guided Decision Table
    《Business rules engine - Java》

    image
  • Guided Rule Editor
    《Business rules engine - Java》

    image
  • Test Running
    《Business rules engine - Java》

    image

其他语言的简单调研

Groovy

http://www.howardism.org/Technical/Groovy/RulesEngine.html
https://github.com/zhaber/grules

Documents
https://www.slideshare.net/paulk_asert/groovy-rules

Javascript

http://www.inrule.com/products/inrule-for-javascript/
https://npmjs.org/package/nools
https://github.com/anywhichway/rule-reactor
https://code.google.com/p/jsonrules/
https://www.npmjs.com/package/business-rules-engine

Documents
https://rushfrisby.com/evolution-of-the-javascript-rule-engine/
http://www.flexrule.com/archives/javascript-rules-engine/
https://codeontime.com/learn/business-rules/javascript/validation

后记

完成初稿后,随即看到这篇文章《携程在线风控系统架构》,文中提到Drools的使用。

风控3.0(Aegis)
Aegis开始使用Drools脚本用于规则的编写,极大的提高了规则团队对突发事件的响应时间,紧急规则一般10分钟就能上线。
脚本执行引擎切换Drools到Java
使用模版屏蔽编写规则时drools的特殊语法,之后将脚本编译成Java class执行。规则的执行性能提升1倍,整个引擎的实时平均耗时降入100ms。

点赞