Drools Spring improvements

Bauna (Pablo Nussembaum) and I have been working on improving the Drools Spring integration that Mark committed some weeks ago. We have changed the approach a little bit to make it more Spring friendly and to use the ServiceManager(SM) from Drools-vsm. in that way, you will be able to create local or remote instances of kbases and ksessions transparently depending on the SM implementation configured.

So let’s dive directly into the new bean.xml:


<bean id="sm1" class="org.drools.vsm.local.ServiceManagerLocalClient" />

<drools:kbase id="kbase1" serviceManager="sm1">
<drools:resource type="DRL" source="classpath:org/drools/container/spring/testSpring.drl"/>
<drools:resource source="classpath:org/drools/container/spring/IntegrationExampleTest.xls" type="DTABLE">
<drools:decisiontable-conf input-type="XLS" worksheet-name="Tables_2" />
</drools:resource>
</drools:kbase>

<drools:ksession id="ksession1" type="stateless" name="stateless1" kbase="kbase1" serviceManager="sm1"/>
<drools:ksession id="ksession2" type="stateful" kbase="kbase1" serviceManager="sm1"/>

As we can see the first change is that instead of registering sessions inside an SM, the SM is injected into kbases and ksessions.
in the case of defining a kbase you need to provide an SM from which it will be created. But now we’ve made serviceManager optional, when an SM isn’t provided it’ll create a ServiceManagerLocalClient internally.
Another change we’ve made is that ksessions are auto-registered into the SM when one is provided. You also have the option of providing a name if you don’t want to use the bean id when registering it to an SM. As such the above example can be rewritten as:


<drools:kbase id="kbase1">
<drools:resource type="DRL" source="classpath:org/drools/container/spring/testSpring.drl"/>
<drools:resource source="classpath:org/drools/container/spring/IntegrationExampleTest.xls" type="DTABLE">
<drools:decisiontable-conf input-type="XLS" worksheet-name="Tables_2" />
</drools:resource>
</drools:kbase>

<drools:ksession id="ksession1" type="stateless" kbase="kbase1"/>
<drools:ksession id="ksession2" type="stateful" kbase="kbase1"/>

As a working demonstration we updated the camel pipeline example to make use of the changes we’ve made.

Enjoy!

Download the updated example project: Drools Camel Spring

Author

Comments are closed.