<div dir="ltr"><div><div><div><div><div><div><div><div>I'm testing the drools new version (6.1.0.Beta4) but I have a problem with the Stateful Drools Session.<br><br></div>I have deployed in JBoss Fuse ESB the last versión of the drools (drools camel, jbpm, spring, etc), I have atached my camel context bundle (It's a maven project). <br>
<br></div>This is my camel-context<br><br><?xml version="1.0" encoding="UTF-8"?><br><beans xmlns="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>"<br>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br> xmlns:kie="<a href="http://drools.org/schema/kie-spring">http://drools.org/schema/kie-spring</a>"<br>
xsi:schemaLocation="<br> <a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a> <br> <a href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</a><br>
<a href="http://drools.org/schema/kie-spring">http://drools.org/schema/kie-spring</a> <a href="http://drools.org/schema/kie-spring.xsd">http://drools.org/schema/kie-spring.xsd</a><br> <a href="http://camel.apache.org/schema/spring">http://camel.apache.org/schema/spring</a> <a href="http://camel.apache.org/schema/spring/camel-spring.xsd">http://camel.apache.org/schema/spring/camel-spring.xsd</a>"><br>
<br> <br> <br> <kie:kmodule id="kModule"><br> <kie:kbase name="rules" packages="rules"><br> <kie:ksession name="ksession1" type="stateful"> <br>
<!--<kie:batch><br> <kie:fire-all-rules/><br> </kie:batch> --> <br> <kie:configuration><br> <kie:jpa-persistence><br>
<kie:transaction-manager ref="txManager"/><br> <kie:entity-manager-factory ref="myEmf"/><br> </kie:jpa-persistence> <br>
</kie:configuration><br> <br> <br> </kie:ksession><br> </kie:kbase><br> </kie:kmodule><br><br> <kie:environment id="env"><br>
<kie:entity-manager-factory ref="myEmf"/><br> <kie:transaction-manager ref="txManager"/><br> </kie:environment><br><br> <br> <bean class="org.postgresql.ds.PGPoolingDataSource" id="jbpm-ds"><br>
<property name="serverName" value="localhost"></property><br> <property name="databaseName" value="drools"></property><br> <property name="portNumber" value="5432"></property><br>
<property name="user" value="DWP"></property><br> <property name="password" value="DWP"></property><br> </bean><br> <br> <br> <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><br>
<property name="dataSource" ref="jbpm-ds"/><br> <property name="persistenceUnitName" value="org.jbpm.persistence.jpa.local"/><br> </bean><br><br>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"><br> <property name="entityManagerFactory" ref="myEmf"/><br> </bean><br>
<br> <bean id="kiePostProcessor" class="org.drools.osgi.spring.OsgiKModuleBeanFactoryPostProcessor"/><br><br> <bean id="fireALlRulesCommand" class="com.execute.command.FireAllRules"/><br>
<br> <camelContext xmlns="<a href="http://camel.apache.org/schema/spring">http://camel.apache.org/schema/spring</a>"><br> <route trace="false" id="testRoute"><br> <from uri="timer:testRoute?period=10s"/><br>
<to uri="log:message"/><br> <to uri="kie:ksession1?action=insertBody" id="AgeVerification"/><br> <br> <bean method="fireAllRules" ref="fireALlRulesCommand"/> <br>
<to uri="kie:ksession1?action=execute"/><br> <br> </route><br> </camelContext> <br> <br></beans><br><br></div>As you can see it is an scenario where Drools is in an stateful session with persistence configured. <br>
<br>The bundle is executed without errors but I want that Drools executes my rules each time that the route is executed ( fireUntilHalt mode but I wasn't able as seems that this command is not availble in a persisted environment ), for this reason I've created a bean with the command: fireAllRules and I use <to uri="kie:ksession1?action=execute"/> to execute the rules but the problem is that the rules are only executed the first time, only the first time and never in subsequents executions of the route.<br>
<br> The persistece seems to work well ( I can see the datamodel created and populated as expeted in the DB ). <br><br>However if I change to use stateless mode ( no persistence then ), the rules are executed each time that route is executed ( as expected ), and therefore I don´t need the command fireAllRules<br>
<bean method="fireAllRules" ref="fireALlRulesCommand"/> <br> <to uri="kie:ksession1?action=execute"/><br><br><br><br></div>Questions:<br><br></div>Is it possible to have a stateful fireUntilHalt drools session that keeps using the same knowledge session in subsequent camel route executions?<br>
<br></div>If it is not possible, Can I have a stateful ( persisted )drools session and invoke "fireAllRules" whenever I make changes in the knowledge session ( new Facts are inserted )?<br><br></div>I've deep dived into the web looking for examples or documentation of this scenario both in Spring and Blueprint. Does anyone of you have any pointers to documentation on the matter?<br>
<br></div>Kind Regards,<br></div>