我想,我需要一个简单的规则引擎? [英] I need a simple rules engine, I think?

查看:182
本文介绍了我想,我需要一个简单的规则引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于解决这个问题的最佳方法的建议。

I need some advice on the best approach to solving this problem.

我研究了DROOLS,Java Rule Engine和其他一些。所有这些都是强大的,并且对它们有好处。我不知道哪个(如果有的话)对我来说是最好的选择。

I've researched DROOLS, Java Rule Engine and a few others. All of these are powerful, and have good things about them. I don't know which (if any) will be the best choice for me.

我有一个业务对象。 (简化演示)

I have one business object. (simplified for demo)

Person
     firstName:String
     lastName:String
     departMent:String
     hireDate:Date

我需要在Web应用程序中编写一个允许编辑的编辑器适用于围绕这些领域构建的复杂规则。我需要支持复杂的嵌套AND / OR逻辑。我只需要基本的运算符,规则应该简单地评估为真或假。如果规则评估为真或假,则将分别执行一个操作。

I need to write an editor in a web application that will allow for complex rules to be built around these fields. I need to support complex nested AND/OR logic. I just need basic operators, and the rule should simply evaluate to true or false. If the rule evaluates to true or false, one action will occur respectively.

例如,


firstName CONTAINSvalueAND
(lastName EQUALSinputOR department
CONTAINSinput)

firstName CONTAINS "value" AND (lastName EQUALS "input" OR department CONTAINS "input")

我原以为,也许我应该编写自己的解析器并在我自己的代码中评估逻辑。我不知道该怎么做,任何建议或链接到阅读的东西将不胜感激。我可以研究一种特定的设计模式吗?

I had thought, maybe I should just write my own parser and evaluate the logic in my own code. I don't know what to do, any advice or links to something to read would be greatly appreciated. Is there a specific design pattern I could research?

您如何解决这个问题?关于规则引擎的一个保留是,它们可能太复杂而不仅仅是一个简单的问题吗?

How would you solve this problem? One reservations about the rules engines is that maybe they are too complex for just a simple problem?

推荐答案

这不是肯定/毫无疑问,但我可以分享我的经验,并希望它有所帮助。
我在一些项目中非常成功地使用了DROOLS。除了一些情况(另一个团队在重载下遇到DROOLS问题),DROOLS是一个非常有用的库。

This is not an yes/no question, but I can probably share my experiences, and hope it helps. I have used DROOLS quite successfully in a few projects. Apart from some cases (another team had issues with DROOLS under heavy load,) DROOLS is quite an useful library.

我构建了一个应用程序:

1.从源读取输入

2.根据一组可用操作的输入选择下一个操作

I built an application which:
1. read input from a source
2. chose the next action based on the input from a set of available operations

As看起来微不足道,它需要非常灵活:

1.输入是一组变量名称 - 值对,名称未预先确定。

2.值,存在/缺少某些名称/值(基于事件的发生/不存在),触发不同的操作。

3.业务规则可以在应用程序运行时更改。

As trivial as it looks, it needed to be very flexible:
1. The input was a variable set of name-value pairs, names not predetermined.
2. values, presence/absence of certain name/values (based on occurrence/absence of events), trigger different actions.
3. The business rules can change while the application is running.

也许有更好的解决方案,但无论好坏,我最终都使用了DROOLS。我开发了一个BPEL,由DROOLS组件做出决策。 DROOLS组件在内部从Microsoft Excel电子表格中读取决策制定规则。如果文件发生更改,它会重建规则。
现在领域专家会在需要时更改此电子表格,我们不会经历痛苦的​​部署!

Maybe there are better solutions, but for better or worse, I ended up using DROOLS. I developed a BPEL in which the decisions are made by the DROOLS component. The DROOLS component internally reads the decision making rules from a Microsoft Excel spreadsheet. It rebuilds the rules if there is a change in the file. Now the domain experts change this spreadsheet when required, and we do not go through painful deployments!

如果您需要复杂的用户界面,DROOLS Guvnor很容易可用的网络应用程序(具有丰富的用户界面),可帮助您的域/主题专家构建规则并将其存储在数据库中。

If you want a sophisticated UI, DROOLS Guvnor is a readily available web-application (with rich UI,) which would help your domain/subject-matter experts to build rules and store them in a database.

这篇关于我想,我需要一个简单的规则引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆