Drools
Drools is a Business Rule Management System (BRMS) solution. It provides a rule engine which processes facts and produces output as a result of rules and facts processing. Centralization of business logic makes it possible to introduce changes fast and cheap.
What are Drools Basic?
We are going to look into Drool basic concepts
Facts — represents data that serves as input for rules
Working Memory — a storage with Facts, where they are used for pattern matching and can be modified, inserted and removed
Rule — represents a single rule which associates Facts with matching actions. It can be written in Drools Rule Language in the .drl files or as Decision Table in an excel spreadsheet.
Knowledge Session — it holds all the resources required for firing rules; all Facts are inserted into session, and then matching rules are fired
Knowledge Base — represents the knowledge in the Drools ecosystem, it has the information about the resources where Rules are found, and also it creates the Knowledge Session
Module — A module holds multiple Knowledge Bases which can hold different sessions
领英推荐
Let’s understand Drool keyword
package — this is the package name we specify in the kmodule.xml, the rule file is located inside this package
import — this is similar to Java import statement, here we need to specify the classes which we are inserting in the KnowledgeSession
global — this is used to define a global level variable for a session; this can be used to pass input parameter or to get an output parameter to summarize the information for a session
Rule: A rule is nothing but the logic that will be applied to incoming data. It has two main parts: when and then.
When: Determines the condition on which the Rule will be fired.
Then: The action; if the rules met the condition, they defines what work this rule performs.
Conclusion:
We have explored making use of Drools as a business rule engine in our application. There are multiple way of writing rules, we can also use decision tables which provide capability of defining rule in pre-formatted Excel sheet.