问题
I am using the drools server 5.5 Final with Spring to configure the knowledge session to persist to database(mysql) and expect it will reload the session when server(tomcat) restart. code snippet as below
<drools:resource-change-scanner id="s1" interval="5" enabled="true" />
<drools:grid-node id="node1"/>
<drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
<drools:resources>
<drools:resource type="DRL" source="file:///tmp/test.drl"/>
</drools:resources>
</drools:kagent>
<drools:kbase id="kbase1" node="node1">
</drools:kbase>
<drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1">
<drools:configuration>
<drools:jpa-persistence>
<drools:transaction-manager ref="txManager" />
<drools:entity-manager-factory ref="myEmf" />
</drools:jpa-persistence>
</drools:configuration>
</drools:ksession>
I can see it will insert the session info to Mysql when Tomcat restart each time
How to configure to reload the session from Database if the session has been persisted before?
回答1:
Finally, we happen to see the src code of KnowledgeSessionDefinitionParser which will parse the spring configuration file http://grepcode.com/file/repo1.maven.org/maven2/org.drools/drools-spring/5.5.0.Final/org/drools/container/spring/namespace/KnowledgeSessionDefinitionParser.java?av=f
in the code, it will get the value of 'load' attribute and use as the sessionId to reload. so we tested to add load="sessionId" and it is ok to reload. but if config the sessionId to a number which does not exist in the DB, it will throw exception
<drools:ksession id="ksession1" type="stateful" kbase="kbase1" node="node1">
<drools:configuration>
<drools:jpa-persistence load="42011">
<drools:transaction-manager ref="txManager" />
<drools:entity-manager-factory ref="myEmf" />
</drools:jpa-persistence>
</drools:configuration>
</drools:ksession>
For a real application, it is impossible to know the sessionId when do the src configuration, also have not found drools have provided any way for us to pre-set the sessionId.
so is it the correct solution? Any one have advanced opinion?
来源:https://stackoverflow.com/questions/21928187/how-to-configure-to-reload-the-drools-knowledge-session-when-servertomcat-rest