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:

File validation

  1. structure
  2. field format
  3. interdependencies
  4. accumulators
  5. headers and trailers

Data Validation

  1. interdependencies
  2. database comparators

Compliance

  1. EU compliance
  2. PCI compliance

Calculations

  1. Account balances
  2. Issuer charges and entitlements
  3. Acquirer charges and entitlements

Logging

  1. Errors
  2. Warnings
  3. Audit
  4. Compliance

Persistence

  1. Inserts
  2. Updates

 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!

And so…

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s