Control business rules execution from your processes

Business processes benefit a lot from business rules, actually they are like must to have in today's constantly changing world. jBPM comes with excellent integration with Drools so that already has a lot of advantages to provide multiple levels of business rules integration:

  • BPMN2 Business Rule task
  • Conditional events (start, intermediate and boundary)
  • Sequence flow conditions

Default integration with rules is that process engine shares the same working memory with rules engine. That in many cases is desired but the main limitations is life cycle of rules and processes are tightly coupled - they are part of the same project (aka kjar) or in other words knowledge base. 

This in turn makes it harder to decouple it and manage life cycle of business rules independently. There are domains out there that have much higher frequency of change in the rules rather than in processes so this tight integration makes it hard to easily upgrade rules without affecting processes - keep in mind that processes are usually long running and can't be easily migrated to next version just because of rule changes.

To resolve this, alternative way of dealing with business rules from within process has been introduced. It does support only business rule tasks and not conditional events or sequence flow conditions. 

What's in the toolbox?

This new feature introduces two new components that serve different use cases:
  • Business Rule Task based on work item handler
  • Remote Business Rule Task based on work item handler and Kie Server Client
Both of them support two types of rule evaluation:
  • DRL
  • DMN 
Let's look at them in details, starting first with Business Rule Task handler.

Business Rule Task handler

Main use case for this alternative business rule task is to decouple process knowledge base from rule knowledge base. That means we will have two projects - kjars to be responsible for handling these two business assets. Rule project is solely responsible for defining business rules which can then be updated at any time without affecting processes. 

Next process project (kjar) does focus only on business processes and hand rule evaluation to the rule project. The only common place is that Business Rule Task handler that defines what kjar (rule project) should be used within process project. 

Since the alternative business rule task is based on work item node, it requires work item handler to be registered in process project. As usual work item is registered in deployment descriptor (accessible via project editor)

Business Rule Task handler is implemented by org.jbpm.process.workitem.bpmn2.BusinessRuleTaskHandler and it expects following arguments:
  • groupId - mandatory argument referring to rule's project groupId
  • artefactId - mandatory argument referring to rule's project artefactId
  • version - mandatory argument referring to rule's project version 
  • scanner interval - optional used to schedule periodic scans for rules updates - in milliseconds
Business Rule Task handler supports two types of rule evaluation:
  • DRL - that allows to specify following data input on task level to control its execution
    • Language - set to DRL
    • KieSessionName - name of the kie session as defined in kmodule.xml of rule project - can be left empty which means default kie session is used
    • KieSessionType - stateless or stateful - stateless is default if not given
    • all other data inputs will be inserted into working memory as facts thus will be available for rule evaluation. Note that data input and output should be matched by name to properly retrieve updated facts and put back into process variables
  • DMN - that allows to specify following as data input on task level:
    • Language - set to DMN
    • Namespace - DMN namespace to be used
    • Model - model to be used
    • Decision - optional decision name to be used
    • all other data inputs are added to DMN context for evaluation. All results from DMNResult are available as data outputs referred by name as defined in DMN
NOTE: Since projects are decoupled they need to have common data model that both will operate on. Currently that model must be on parent class loader instead of kjar level due to classes being loaded by different class loaders and thus making rules not match them properly. In case of execution server (KIE Server) model jar must be added to WEB-INF/lib of the KIE Server app and added to both projects as dependency in provided scope.

    Remote Business Rule Task handler

    Remote flavour of the handler comes with KIE Server Client and aims at providing even more decoupling as it will communicate with external decision service (KIE Server) to evaluate rules. This provide more flexibility and removes the limitation of common data model to be present on the application level. With remote business rule task users can simply define model project as project dependency (with default scope) for both projects - rules and processes. Since there is marshalling involved there is no problem with class loaders and thus working as expected.

    From project authoring point of view there is only one difference - Business Rule Task requires additional data input - ContainerId that defines which container on execution server it should target. Obviously this can be container alias as well for more flexibility.

    Similar as Business Rule Task, this handler supports both DRL and DMN. Depending on which type is needed it supports different data inputs:
    • DRL
      • Language - DRL
      • ContainerId - container id or alias of the container to be used to evaluate rules
      • KieSessionName - name of the kie session on execution server for given container
    • DMN
      • Language - DMN
      • ContainerId - container id or alias of the container to be used to evaluate rules
      • Namespace - DMN namespace to be used
      • Model - model to be used
      • Decision - optional decision name to be used
    Any other data input will be send as data to the execution server. Results handling is exactly the same as with Business Rule Task handler.

    Remote Business Task Handler is implemented by org.kie.server.client.integration.RemoteBusinessRuleTaskHandler. Handler expects following arguments:
    • serverUrl - location of the execution server that this handler should use, it can be comma separated list of URLs that will be used by load balancer
    • username - user to be used to authenticate calls to execution server
    • password - password to be used to authenticate calls to execution server
    • classLoader - projects class loader to gain access to custom types 

    Registration of the handler is done exactly the same, via deployment descriptor. 

    That would conclude the description of new capabilities. If you'd like to try it yourself simply clone this repository to your workbench, build and run it!

    Here you can see this being done...

    That's all for now, though stay tuned as more will come :)


    1. Hey Maciej, is there a way to fetch all the rules from Drools Workbench using rest api?

      1. do you mean rule as definitions? if so there is no such endpoints but why would you need one?

    2. This comment has been removed by the author.

    3. Hi Maciej, in 7.6.0.Final release, I am observing that Business Rule Task is not invoking rule engine either through BusinessRuleTaskHandler or RemoteBusinessRuleTaskHandler. The Rule only get executed if the drl file is part of same project as the case itself. Unfortunately i don't see anything in log to figure out what might be missing here.

      Any suggestions?

      1. you need to provide more details as this has no context to base the answer on

    4. Hi Maciej, Thanks for your reply. I have provided more details in a new thread in Jbpm Usage group with subject "JBPM Case with Business Rule task"


    5. How to execute multiple workitemitemhandler? currently only one itemhandhander executes and next itemhandler doesn't start after the first workitemhandler

    6. I can see that you are putting a lot of efforts into your blog. Keep posting the good work. Some really helpful information in there. Nice to see your site.
      A Social Media, Public Relations and Influencer Marketing Agency

    7. Wow, Fantastic Blog, it’s so helpful to me, and your blog is very good, I’ve learned a lot from your blog here, Keep on going, my friend; I will keep an eye on it.
      Aircraft Warning Lights | Aviation warning lighting - CEL

    8. This comment has been removed by the author.

    9. Thank you for sharing information. Great blog and great post.Its extremely supportive for me, waiting for a more new post. Continue Blogging!

      Building A Business & opening a business

    10. Great! Thanks for sharing this information
      Business Rules Engine

    11. I am grateful to you on the grounds that your article is exceptionally useful for me to continue with my exploration in same region. Your cited illustrations are all that much significant to my exploration field.This is extraordinary! It really exhibits to me where to broaden my online diary

    12. I constantly like to read a top quality content having accurate info pertaining to the subject and the exact same thing I found in this article. Nice job.
      C-TPAT ที่ปรึกษา

    13. Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and I will surely implement them in my study. Keep blogging article like this.
      See the full guidelines on company registration mlaysia

    14. Sometime few educational blogs become very helpful while getting relevant and new information related to your targeted area. As I found this blog and appreciate the information delivered to my database.
      Ablerex UPS RS SERIES

    15. Thanks for sharing this. This part is really helps me "Business Rule Task handler"
      these are also helps to businessman, Company secretary in Malaysia

    16. Actually, I am facing some difficulties to understand the meaning of the blog. If you have any short video film related to your blog, then I would request you to share here. It would be great help.

    17. I am thankful to this blog for assisting me. I added some specified clues which are really important for me to use them in my writing skill. Really helpful stuff made by this blog.
      bioresonantie almere

    18. I am grateful for this blog to distribute knowledge about this significant topic. Here I found different segments and now I am going to use these new instructions with new enthusiasm.
      reclamebureau amsterdam