简体   繁体   English

数据驱动规则引擎 - 流口水

[英]Data Driven Rules Engine - Drools

I have been evaluating Drools as a Rules Engine for use in our Business Web Application. 我一直在评估Drools作为规则引擎,用于我们的业务Web应用程序。

My use case is a Order Management Application. 我的用例是订单管理应用程序。
And the rules are of following kind: 规则如下:
- If User Type is "SPECIAL" give an extra 5% discount. - 如果用户类型为“特殊”,则额外提供5%的折扣。
- If User has made 10+ Purchases already, give an extra 3% discount. - 如果用户已经进行了10次以上的购买,请额外享受3%的折扣。
- If Product Category is "OLD", give a Gift Hamper to the user worth $5. - 如果产品类别为“旧”,请向价值5美元的用户赠送礼品篮。
- If Product Category is "NEW", give a Gift Hamper to the user worth $1 - 如果产品类别为“新”,请向价值1美元的用户赠送礼品篮
- If User has made purchases of over $1000 in the past, Shipping is Free - 如果用户过去购物超过1000美元,则免运费

The immediate challenge i see is that: 我看到的直接挑战是:
- There is no meaningful UI that i can offer to the end users to modify the rules. - 我可以向最终用户提供修改规则的有意义的UI。
- Guvnor UI or any Editor to modify drl files is just not acceptable from end user point of view - Most of these Rules will operate on often huge data available in db - 从最终用户的角度来看,Guvnor UI或任何修改drl文件的编辑器都是不可接受的 - 这些规则中的大多数都将在db中可用的大量数据上运行

So, 所以,
- I want a way for Admin users to specify these Rule from within my Web App UI. - 我想让管理员用户在我的Web App UI中指定这些规则。
- Could i store these "Rules" in database, and then operate on them via Drools - at least that allows me to "modify" these Rules via my "own" UI. - 我可以将这些“规则”存储在数据库中,然后通过Drools对它们进行操作 - 至少允许我通过“自己的”UI“修改”这些规则。 So this is something like a Decision Table in DB. 所以这就像数据库中的决策表。
- What is the best way to go about this? - 最好的方法是什么?

You asked me to give an answer to your question, given my answer to Data driven business rules . 鉴于我对数据驱动的业务规则的回答,您让我回答您的问题。 My answer to that question was that SQL is a bad solution to execute business rules stored in the database. 我对这个问题的回答是,SQL是执行存储在数据库中的业务规则的糟糕解决方案。 The person who asked that question wanted to generate SQL expressions from their stored business rules, and I cautioned against doing that, because it would lead to problems in security, testability, performance, and maintenance. 问这个问题的人想要从他们存储的业务规则中生成SQL表达式,我告诫不要这样做,因为这会导致安全性,可测试性,性能和维护方面的问题。

I have not used Drools, but I gather from documentation that it includes Guvnor, a business rules manager that supports using an RDBMS as a repository for user-defined rules. 我没有使用过Drools,但是我从文档中收集到它包含了一个业务规则管理器Guvnor,它支持使用RDBMS作为用户定义规则的存储库

[Drools] Guvnor uses the JCR standard for storing assets such as rules. [Drools] Guvnor使用JCR标准存储规则等资产。 The default implementation is Apache Jackrabbit, http://jackrabbit.apache.org . 默认实现是Apache Jackrabbit, http://jackrabbit.apache.org This includes an out of the box storage engine/database, which you can use as is, or configure to use an existing RDBMS if needed. 这包括现成的存储引擎/数据库,您可以按原样使用,或者根据需要配置为使用现有的RDBMS。 ( http://docs.jboss.org/drools/release/5.2.0.Final/drools-guvnor-docs/html/chap-database_configuration.html ) http://docs.jboss.org/drools/release/5.2.0.Final/drools-guvnor-docs/html/chap-database_configuration.html

Apache Jackrabbit is not an RDBMS, it is "a content repository is a hierarchical content store with support for structured and unstructured content, full text search, versioning, transactions, observation, and more." Apache Jackrabbit不是RDBMS,它是“内容存储库是一个分层内容存储库,支持结构化和非结构化内容,全文搜索,版本控制,事务,观察等等。” This seems like a more appropriate repository for Drools. 对于Drools来说,这似乎是一个更合适的存储库。

But Drools doesn't say it tries to use SQL to execute those business rules. 但Drools并没有说它试图使用SQL来执行这些业务规则。 It has a separate component, Drools Expert (Rules Engine) to do that. 它有一个单独的组件, Drools Expert(规则引擎)来做到这一点。

Drools Expert is a declarative, rule based, coding environment. Drools Expert是一个基于规则的声明式编码环境。 This allows you to focus on "what it is you want to do", and not the "how to do this". 这使您可以专注于“你想做什么”,而不是“如何做到这一点”。 ( http://www.jboss.org/drools/drools-expert.html ) http://www.jboss.org/drools/drools-expert.html

SQL is also a declarative programming language, but it's designed to perform relational operations on table-structured data. SQL也是一种声明性编程语言,但它旨在对表结构化数据执行关系操作。 A language to implement a rules engine has different goals, and can probably do things that SQL can't (and vice-versa). 实现规则引擎的语言有不同的目标,并且可能做SQL无法做到的事情(反之亦然)。

So I would suggest if you use Drools, feel free to use an RDBMS as a repository as they document (use their JCR-compliant implementation of content repository, do not try to design your own). 所以我建议如果你使用Drools,随意使用RDBMS作为文档库(使用他们的JCR兼容的内容库实现,不要试图设计自己的)。 Then use their Drools Expert as a specialized language designed for executing rules. 然后使用他们的Drools Expert作为专门用于执行规则的语言。

  • There is no meaningful UI that i can offer to the end users to modify the rules. 我可以向最终用户提供修改规则的有意义的UI。

Out of the box, Guvnor provides web based decision tables (and Excel if you prefer ), as you say you would like to provide. 开箱即用,Guvnor提供基于Web的决策表如果您愿意 ,还提供Excel ),正如您所说的那样。 It provides guided editors for more complex rules, but your rules would appear to be very simple. 它为更复杂的规则提供了指导编辑器 ,但您的规则看起来非常简单。

  • Guvnor UI or any Editor to modify drl files is just not acceptable from end user point of view 从最终用户的角度来看,Guvnor UI或任何修改drl文件的编辑器都是不可接受的

As mentioned, Guvnor supports decision tables. 如上所述,Guvnor支持决策表。 If you don't like the layout of the Guvnor web application, then you can just embed the Guvnor editors into your own web application. 如果您不喜欢Guvnor Web应用程序的布局,那么您可以将Guvnor编辑器嵌入到您自己的Web应用程序中。

  • Most of these Rules will operate on often huge data available in db 这些规则中的大多数将在db中可用的大量数据上运行

The size of your database is irrelevant to the use of Guvnor. 数据库的大小与Guvnor的使用无关。 Guvnor is for editing rules, not runtime evaluation. Guvnor用于编辑规则,而不是运行时评估。 Drools Expert is the runtime rules engine. Drools Expert是运行时规则引擎。 It's fast. 它很快。 It can deal with very large volumes of data and very large volumes of rules. 它可以处理大量数据和大量规则。 All you need to do is write database queries to get relevant chunks of that data into the rules engine at runtime. 您需要做的就是编写数据库查询,以便在运行时将相关的数据块放入规则引擎中。 You need to do that, whatever solution you try to implement. 无论您尝试实施什么解决方案,都需要这样做。

On a side-note, if what you're really after is an explanation of when rules engines are good (and bad) solutions to a problem, then I would recommend reading the Why use a Rule engine? 另外,如果您真正关注的是规则引擎何时是问题的好(和坏)解决方案的解释,那么我建议阅读为什么使用规则引擎? section of the Drools Expert manual. Drools专家手册的一节。

Generally, I've found it is easier to work at a more abstract level, such as a Domain Model, and have some sort of programmatic conversion from that to Drools rules, instead of dealing with Drools rules directly. 一般来说,我发现在更抽象的层面上工作更容易,比如域模型,并且从那里到Drools规则进行某种程序化转换,而不是直接处理Drools规则。 That way, you can store your Domain Model however you like, and you can build UIs around it, etc, and still have the option to generate Drools rules on demand. 这样,您可以根据需要存储域模型,并且可以围绕它构建UI等,并且仍然可以选择按需生成Drools规则。 Then challenge with this is creating a programmatic transformation from your model to Drools rules, but templating tools will help here. 然后挑战就是创建从模型到Drools规则的程序化转换,但模板工具在这里会有所帮助。 I've used Groovy templating for this, and it has worked well. 我已经使用了Groovy模板,它运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM