开发者

Best practices for using Drools Expert/Flow in a Web Application

开发者 https://www.devze.com 2023-01-17 19:52 出处:网络
I\'m currently teaching myself Drools Expert/Flow as well as GWT. I want to use Drools Flow as an event/command bus and business rule engine to achieve loose coupling between different parts of the ap

I'm currently teaching myself Drools Expert/Flow as well as GWT. I want to use Drools Flow as an event/command bus and business rule engine to achieve loose coupling between different parts of the application.

So far开发者_开发技巧 I've gotten both Expert and Flow working from my test cases, but I have a hard time figuring how to best implement Flows within a web container.

Should I put all the scaffolding into an Stateless Session EJB and let each request set up everything from scratch and then run the flows/rules? This seems like a waste of resources to me. Can I instead store a single knowledge session and share that sessions between web requests, accessing it concurrently, would that scenario scale and is it thread safe (my guess is no)? Is pooling knowledge sessions a good idea?

What I'm asking for is basically if there is any best practices for the above? The documentation and examples, while otherwise quite good, are not clear on these particular points.

I did read something about Drools Grid, not sure if that would solve my problem and that seems to be under development. If my questions are unclear, please say so.

BR Magnus


A KnowledgeBase is thread safe and heavy weight (it's not cheap to create), so you 'll probably want to keep that in an application scope.

For now, most people tend to use a stateless architecture and create a StatelessKnowlegdeSession (thread unsafe and cheap to create) for every web request, for example in a stateless session bean (or a seam/CDI bean or a spring bean). However, if you have the power of stateful EJB's, it can be rewarding to keep use one StafefulKnowlegdeSession to handle all requests in the same conversation.

I am not sure if StatefulKnowlegdeSession is thread safe (don't think so), so I made an issue: https://issues.jboss.org/browse/JBRULES-2842

0

精彩评论

暂无评论...
验证码 换一张
取 消