Using Drools drl file with common functions in 2 separate kbase/ksessions

廉价感情. 提交于 2021-02-10 20:47:51

问题


using Drools 6.2.0.Final we have a rules project with 2 separate kbases and ksessions configured like this in the kmodule.xml:

<kbase name="kbase1"
      packages="foo.bar.package1">
    <ksession name="ksession1" type="stateless" />
</kbase>

<kbase name="kbase2"
        packages="foo.bar.package2">
  <ksession name="ksession2" type="stateless" />
</kbase>

In each of these packages we have a number of .drl files that contain some business rules. In addition to those each package contains a .drl containing functions that are called from the business rules files, e.g. package1-functions.drl and package2-functions.drl. Since the content of these 2 function files is identical we are thinking about creating a "common" package and have only one copy of the functions file.

However, we have not managed to get our rules to work with the functions being in a separate package.

This is how we configured our kmodule.xml:

<kbase name="common"
    packages="foo.bar.common"/>

<kbase name="kbase1" includes="common"
    packages="foo.bar.package1">
    <ksession name="ksession1" type="stateless" />
</kbase>

<kbase name="kbase2" includes="common"
       packages="foo.bar.package2">
    <ksession name="ksession2" type="stateless" />
</kbase>

Another way we tried was without a "common" kbase but adding the common package to the "packages" attribute in kbase1 and kbase2.

Is it possible to use a common package within 2 other kbases?


回答1:


There is no way a DRL function can be used from another DRL package.

It is possible to have one or more functions on a separate DRL file, and they can be used in any DRL file that is in the same DRL package.

Perhaps you are overrating the importance of DRL packages - you won't have any problems if all DRL files are in the same DRL package.

Alternatively, consider the use of Java static methods.



来源:https://stackoverflow.com/questions/29558086/using-drools-drl-file-with-common-functions-in-2-separate-kbase-ksessions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!