DroolsBasics&Common
Pitfalls
Mauricio Salatino / JBoss - Red Hat
JUG Cork March - 2016
Agenda
● What is Drools?
○ Drools History
○ Rule Engine
○ DRL language
○ Execution Cycle
● KIE - Knowledge is Everything
○ KIE Platform & KIE API
● Our First Drools Project
● Drools Common Usage
● Drools Common Pitfalls
● Roadmap (7.x version)
AboutMe
● Senior Software Engineer @ Red Hat/JBoss
● I joined the Drools & jBPM in 2012
● Passionate about Drools & jBPM
● Author of 3 books about jBPM
● New book about Drools
○ (1st April 2016)
WhatisDrools? -History
● 2003: Created by Mark Proctor and Bob McWhirter
● 2005: Acquired by JBoss
● 2007: Drools 3.x introduced the first version of the Rete
OO Algorithm
● 2009: Drools 4.x focused on performance and production
ready
● 2012: Drools 5.x focused on integration and unification
of Drools, jBPM and CEP (KIE was born)
● 2014: Drools 6.x focused on infrastructure, deployment
and tooling
WhatisDrools?
● It depends on what you need
○ Core: lightweight Rule Engine (a library)
○ KIE Server: standalone - as a service provider
● Rule Engine -> Inference Engine
○ Data Driven -> Forward Chaining Algorithms
○ Goal Driven -> Backward Chaining Algorithms
● Change of paradigm from Imperative (Java) to Declarative
WhatisDrools?-RuleStructure
rule “Large Orders require approval”
//<rule attributes>
when
Order(items.size >= 10 && total >= 100000)
then
// Trigger approval process
end
WhatisDrools?-RuleENgineOverview
WhatisDrools? -RuleExecutionCycle
KIEPlatform
● Drools
● Drools CEP (Fusion)
● jBPM
● OptaPlanner
● KIE Server (Drools, jBPM & CEP unified server)
● Uberfire (uberfireframework.com)
○ KIE Workbench (Drools, jBPM, Optaplanner Authoring, Runtime &
monitoring)
○ KIE Drools Workbench (Drools Authoring)
KIEAPIs
● KieContainer
● KieBase
● KieSession
○ insert(Object)
○ retract(FactHandle)
○ update(FactHandle, Object)
○ fireAllRules() / fireAllRules(int)
● KieScanner
● kmodule.xml
Drools Specific
OurFirstDroolsProject
● Simple JAR Java Maven Project
● Add Maven Dependencies
○ drools-compiler
■ drools-core (transitive)
■ kie-api (transitive)
● CDI Enabled
○ cdi-api
○ weld-se-core
○ beans.xml
● KIE specific
○ kmodule.xml
■ conventions over configurations
RulesPower
● Any Java Model (non-intrusive)
● Filter Data (Simple Filters)
● Correlate Data (Multiple filters between patterns)
● Accumulations / Aggregations (accumulate functions)
● Inference Chain
○ Detailed Log
○ Query Data
○ Truth Maintenance System(TMS)
CommonPitfalls
● Start simple, don’t over complicate things
● Compare with if/else statements
● Too much logic on the RHS
● Infinite Loop
● Complex (Nested) Models - Facts VS Non-Facts
● Cross Product - DB/SQL analogy
● From/Eval executed multiple time in RHS
○ External Service Calls (Sync calls)
● Persistence
Roadmap(7.xseries)
● Cloud Deployments
● Tooling for the Cloud
● Self-service applications
● Different Vertical’s Packages
● API refactoring towards
○ Flexibility
○ Services
○ Composition
● Drools language improvements
● Phreak tuning and fragmentation for distribution
Community
● www.drools.org / www.jbpm.org
● Drools & jBPM Mailing lists
● irc.freenode.net
○ #drools
○ #jbpm
● Blogs:
○ blog.athico.com
○ salaboy.com
Questions?
RETENetwork
Phreak

Cork JUG - Drools basics &amp; pitfalls

  • 1.
    DroolsBasics&Common Pitfalls Mauricio Salatino /JBoss - Red Hat JUG Cork March - 2016
  • 2.
    Agenda ● What isDrools? ○ Drools History ○ Rule Engine ○ DRL language ○ Execution Cycle ● KIE - Knowledge is Everything ○ KIE Platform & KIE API ● Our First Drools Project ● Drools Common Usage ● Drools Common Pitfalls ● Roadmap (7.x version)
  • 3.
    AboutMe ● Senior SoftwareEngineer @ Red Hat/JBoss ● I joined the Drools & jBPM in 2012 ● Passionate about Drools & jBPM ● Author of 3 books about jBPM ● New book about Drools ○ (1st April 2016)
  • 4.
    WhatisDrools? -History ● 2003:Created by Mark Proctor and Bob McWhirter ● 2005: Acquired by JBoss ● 2007: Drools 3.x introduced the first version of the Rete OO Algorithm ● 2009: Drools 4.x focused on performance and production ready ● 2012: Drools 5.x focused on integration and unification of Drools, jBPM and CEP (KIE was born) ● 2014: Drools 6.x focused on infrastructure, deployment and tooling
  • 5.
    WhatisDrools? ● It dependson what you need ○ Core: lightweight Rule Engine (a library) ○ KIE Server: standalone - as a service provider ● Rule Engine -> Inference Engine ○ Data Driven -> Forward Chaining Algorithms ○ Goal Driven -> Backward Chaining Algorithms ● Change of paradigm from Imperative (Java) to Declarative
  • 6.
    WhatisDrools?-RuleStructure rule “Large Ordersrequire approval” //<rule attributes> when Order(items.size >= 10 && total >= 100000) then // Trigger approval process end
  • 7.
  • 8.
  • 9.
    KIEPlatform ● Drools ● DroolsCEP (Fusion) ● jBPM ● OptaPlanner ● KIE Server (Drools, jBPM & CEP unified server) ● Uberfire (uberfireframework.com) ○ KIE Workbench (Drools, jBPM, Optaplanner Authoring, Runtime & monitoring) ○ KIE Drools Workbench (Drools Authoring)
  • 10.
    KIEAPIs ● KieContainer ● KieBase ●KieSession ○ insert(Object) ○ retract(FactHandle) ○ update(FactHandle, Object) ○ fireAllRules() / fireAllRules(int) ● KieScanner ● kmodule.xml Drools Specific
  • 11.
    OurFirstDroolsProject ● Simple JARJava Maven Project ● Add Maven Dependencies ○ drools-compiler ■ drools-core (transitive) ■ kie-api (transitive) ● CDI Enabled ○ cdi-api ○ weld-se-core ○ beans.xml ● KIE specific ○ kmodule.xml ■ conventions over configurations
  • 12.
    RulesPower ● Any JavaModel (non-intrusive) ● Filter Data (Simple Filters) ● Correlate Data (Multiple filters between patterns) ● Accumulations / Aggregations (accumulate functions) ● Inference Chain ○ Detailed Log ○ Query Data ○ Truth Maintenance System(TMS)
  • 13.
    CommonPitfalls ● Start simple,don’t over complicate things ● Compare with if/else statements ● Too much logic on the RHS ● Infinite Loop ● Complex (Nested) Models - Facts VS Non-Facts ● Cross Product - DB/SQL analogy ● From/Eval executed multiple time in RHS ○ External Service Calls (Sync calls) ● Persistence
  • 14.
    Roadmap(7.xseries) ● Cloud Deployments ●Tooling for the Cloud ● Self-service applications ● Different Vertical’s Packages ● API refactoring towards ○ Flexibility ○ Services ○ Composition ● Drools language improvements ● Phreak tuning and fragmentation for distribution
  • 15.
    Community ● www.drools.org /www.jbpm.org ● Drools & jBPM Mailing lists ● irc.freenode.net ○ #drools ○ #jbpm ● Blogs: ○ blog.athico.com ○ salaboy.com
  • 16.
  • 17.
  • 18.