Blog Posts BPMN DMN

Upgrade Drools version

Blog: Drools & jBPM Blog

We sometimes see questions regarding Drools version upgrade. Most of those questions are about how to change the old API usage in Drools 5 or 6. In this article, I’m going to guide how to change your code to work with the latest Drools version (7.70.0.Final as of now).

API

If you are using old style APIs, it would be like this.

Drools 5
https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-old-API-5.5.0/src/main/java/com/sample/DroolsTest.java

Drools 6
https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-old-API-6.2.0/src/main/java/com/sample/DroolsTest.java

Since Drools 6, we have introduced new KIE APIs. So the old APIs are considered as internal APIs that are not recommended to use in user applications.

In Drools 7, technically, we can write in a similar style.

https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-old-API-7.70/src/main/java/com/sample/DroolsTest.java

However, I write this example not to recommend you write in this style. Just to show a kind of bridge between old APIs and new KIE APIs.

In all the above examples, you build a package and give the package to a kbase.

In the new KIE APIs, the procedure is encapsulated in KieContainer.

Please have a look at the new KIE APIs style.

"Basic DRL"
https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-basic-drl-7.61/src/test/java/com/sample/DroolsTest.java

"Kjar and Runner"
https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-basic-kjar-runner-7.61/src/test/java/com/sample/DroolsTest.java

"Programmatically create a Kjar"
https://github.com/tkobayas/kiegroup-examples/blob/master/Ex-KieFileSystem-7.61/src/test/java/com/sample/DroolsTest.java

For details, please refer to the blog post.

If you have all rules in classpath (e.g. inside an application), "Basic DRL" would be the easiest example.

If you had rules in serialized PKGs, you would choose "Kjar and Runner" approach.

If you want to programmatically manage resource files, "Programmatically create a Kjar" would fit.

Some configuration classes might be moved to different packages or even removed. If you have any doubt, feel free to ask in community channels (https://groups.google.com/g/drools-usage , https://groups.google.com/g/drools-setup , https://kie.zulipchat.com/#narrow/stream/232677-drools).

Rules

DRL and XLS spreadsheets are basically backward compatible. So you can use rule assets in Drools 7.

But there is one caveat, "Property reactivity".

Property reactivity was introduced since Drools 5.4 but it was not enabled by default. However, it’s enabled by default since Drools 7. It means you may see that rules react differently when you upgrade the version. In that case, try to disable the feature and check if the different behaviour was caused by property reactivity.

https://docs.drools.org/latest/drools-docs/html_single/#_property_reactivity_enabled_by_default

If that is the case, you have 2 options.

A. Keep property reactivity disabled

B. Enable property reactivity and review your rules to meet property reactivity behaviour

Property reactivity a powerful feature which allows you to write rules naturally and also provide good performance. Please refer to this section for details.

https://docs.drools.org/latest/drools-docs/html_single/#property-change-listeners-con_decision-engine

Conclusion

Upgrading versions is a key maintenance action of open source software use. Please don’t hegitate!

The post Upgrade Drools version appeared first on KIE Community.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/upgrade-drools-version/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×