<div dir="ltr"><div><div><div><div><div><div><div><div>I&#39;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&#39;s a maven project). <br>
<br></div>This is my camel-context<br><br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;beans xmlns=&quot;<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>&quot;<br>
       xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br>       xmlns:kie=&quot;<a href="http://drools.org/schema/kie-spring">http://drools.org/schema/kie-spring</a>&quot;<br>
       xsi:schemaLocation=&quot;<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>&quot;&gt;<br>
       <br>        <br>    <br> &lt;kie:kmodule id=&quot;kModule&quot;&gt;<br>        &lt;kie:kbase name=&quot;rules&quot; packages=&quot;rules&quot;&gt;<br>            &lt;kie:ksession name=&quot;ksession1&quot; type=&quot;stateful&quot;&gt;    <br>
            &lt;!--&lt;kie:batch&gt;<br>               &lt;kie:fire-all-rules/&gt;<br>               &lt;/kie:batch&gt; --&gt;            <br>            &lt;kie:configuration&gt;<br>                &lt;kie:jpa-persistence&gt;<br>
                    &lt;kie:transaction-manager ref=&quot;txManager&quot;/&gt;<br>                    &lt;kie:entity-manager-factory ref=&quot;myEmf&quot;/&gt;<br>                &lt;/kie:jpa-persistence&gt;                <br>
            &lt;/kie:configuration&gt;<br>            <br>            <br>            &lt;/kie:ksession&gt;<br>        &lt;/kie:kbase&gt;<br>    &lt;/kie:kmodule&gt;<br><br>    &lt;kie:environment id=&quot;env&quot;&gt;<br>
       &lt;kie:entity-manager-factory ref=&quot;myEmf&quot;/&gt;<br>        &lt;kie:transaction-manager ref=&quot;txManager&quot;/&gt;<br>    &lt;/kie:environment&gt;<br><br>  <br>  &lt;bean class=&quot;org.postgresql.ds.PGPoolingDataSource&quot; id=&quot;jbpm-ds&quot;&gt;<br>
   &lt;property name=&quot;serverName&quot; value=&quot;localhost&quot;&gt;&lt;/property&gt;<br>   &lt;property name=&quot;databaseName&quot; value=&quot;drools&quot;&gt;&lt;/property&gt;<br>   &lt;property name=&quot;portNumber&quot; value=&quot;5432&quot;&gt;&lt;/property&gt;<br>
   &lt;property name=&quot;user&quot; value=&quot;DWP&quot;&gt;&lt;/property&gt;<br>   &lt;property name=&quot;password&quot; value=&quot;DWP&quot;&gt;&lt;/property&gt;<br>  &lt;/bean&gt;<br>  <br>    <br>    &lt;bean id=&quot;myEmf&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;<br>
        &lt;property name=&quot;dataSource&quot; ref=&quot;jbpm-ds&quot;/&gt;<br>        &lt;property name=&quot;persistenceUnitName&quot; value=&quot;org.jbpm.persistence.jpa.local&quot;/&gt;<br>    &lt;/bean&gt;<br><br>
    &lt;bean id=&quot;txManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;<br>        &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;myEmf&quot;/&gt;<br>    &lt;/bean&gt;<br>
<br>    &lt;bean id=&quot;kiePostProcessor&quot; class=&quot;org.drools.osgi.spring.OsgiKModuleBeanFactoryPostProcessor&quot;/&gt;<br><br>    &lt;bean id=&quot;fireALlRulesCommand&quot; class=&quot;com.execute.command.FireAllRules&quot;/&gt;<br>
    <br>  &lt;camelContext xmlns=&quot;<a href="http://camel.apache.org/schema/spring">http://camel.apache.org/schema/spring</a>&quot;&gt;<br>    &lt;route trace=&quot;false&quot; id=&quot;testRoute&quot;&gt;<br>        &lt;from uri=&quot;timer:testRoute?period=10s&quot;/&gt;<br>
         &lt;to uri=&quot;log:message&quot;/&gt;<br>         &lt;to uri=&quot;kie:ksession1?action=insertBody&quot; id=&quot;AgeVerification&quot;/&gt;<br>          <br>         &lt;bean method=&quot;fireAllRules&quot; ref=&quot;fireALlRulesCommand&quot;/&gt; <br>
         &lt;to uri=&quot;kie:ksession1?action=execute&quot;/&gt;<br>        <br>    &lt;/route&gt;<br>  &lt;/camelContext&gt; <br>    <br>&lt;/beans&gt;<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&#39;t able as seems that this command is not availble in a persisted environment ), for this reason I&#39;ve created a bean with the command: fireAllRules and I use &lt;to uri=&quot;kie:ksession1?action=execute&quot;/&gt; 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>
&lt;bean method=&quot;fireAllRules&quot; ref=&quot;fireALlRulesCommand&quot;/&gt; <br> &lt;to uri=&quot;kie:ksession1?action=execute&quot;/&gt;<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 &quot;fireAllRules&quot; whenever I make changes in the knowledge session ( new Facts are inserted )?<br><br></div>I&#39;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>