Like most things in the Java arena, Drools now comes with a plethora of tools and APIs to integrate with just about anything.
But, let’s be honest, Drools Core is where all the magic happens. Everything else just hooks into it somehow, and if you can lift the hood on Drools Core you have access to some incredibly powerful tooling.
Let’s take a look a batch processing.
Most batch systems are basically quite simple
- Read a file
- Process the data
- Persist the data
- Write the logs
And a lot of systems run on just one server.
How simple can we make it?
Well, it’s no good for your CV if you can’t mention buzzwords like Spring, Spring Batch and Hibernate but do you really need them?
How about just Java and Drools, and if you want to distribute your business rules across multiple servers then perhaps Camel and a JMS implementation.
For now, let’s assume just one server and a Cron job that kicks off the batch process.
So, the application need be no more complicated than a Java Application with a background thread that polls an incoming directory for files – if it even needs that.
Where does Drools come in?
To put it simply – to do all your if… then… processing:
- field format
- headers and trailers
- database comparators
- EU compliance
- PCI compliance
- Account balances
- Issuer charges and entitlements
- Acquirer charges and entitlements
What about BPMN?
Do you really need that additional level of complexity? Why not just chain StatelessKnowledgeSessions together using Java.
What about state?
Why not just use helpers to maintain state?
What about allowing multiple rulesets to act on the facts?
Facts are passed by reference so a chain of StatelessKnowledgeSessions working on the same Facts works just as well as AgendaGroups and RuleGroups.
What about rules that rely on config data or balances from the database?
Drools Templates with ResultSets!
What about logging which rules fired?
How about an AgendaEventListener that sets bits! Keeps it comprehensive, and compact!
All in all, very simple solutions can be put together to solve complex event processing using just Drools Core and Java with perhaps a little help from Drools Templates.
The net result:
- Rapid prototyping
- Rapid development
- Fast processing
- Highly maintainable
– John Dunning
* John recently designed and implemented a Drools based batch system for EU Compliance for a major credit card company.
It added less than 5 minutes to the existing batch process and was implemented with so few errors that the cost of those errors to the business was below the £10,000 threshold needed to even report them internally.
Defect turnaround never exceeded an hour.
The system has been running error free for over 6 months.