Upgrade Drools version

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 hesitate!

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments