简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM