Book Image

Instant Drools Starter

By : Jeremy Ary
Book Image

Instant Drools Starter

By: Jeremy Ary

Overview of this book

<p>Drools is a popular business rule management system. The book introduces the concept of rules separation, from what to do to how to do it. This Starter guide supports your development to keep pace with your system’s ever-changing needs, making things simple and easy by taking the rigidity out of complex codes.<br /><br />"Instant Drools Starter" is a practical, hand-on guide that provides you with a number of clear and concise explanations with relatable examples. This book offers step-by-step exercises to help you understand business rule management systems. Learn how they work, how they're best used, and how to perform frequently used tasks and techniques.<br /><br />This Starter guide helps you get familiar with the Drools concept. You will learn to evaluate rules engines and cover all the basics, from rules authoring to troubleshooting. This book highlights the capabilities of the Drools modules.</p> <p><br />After discovering exactly what rules are and what a rule engine brings to the table, we will quickly learn how to install Drools. The guide then explores different tools of the trade and gets you writing your first set of rules instantly. We'll then take those rules, write vital codes piece by piece, and put them into action. In addition, with this guide, learn how to document and troubleshoot everything behind the scenes, as well as developing your rules to the next level. "Instant Drools Starter" will cover everything you need to know to get started, so if you are looking for a complete guide that provides simple solutions to complex problems, look no further.</p>
Table of Contents (7 chapters)

So, what is Drools?


The techie answer guaranteed to get that glazed over look from anyone hounding you for details on project design is that Drools, part of the JBoss Enterprise BRMS product since federating in 2005, is a Business Rule Management System (BRMS) and rules engine written in Java which implements and extends the Rete pattern-matching algorithm within a rules engine capable of both forward and backward chaining inference.

Now, how about an answer fit for someone new to rules engines? After all, you're here to learn the basics, right? Drools is a collection of tools which allow us to separate and reason over logic and data found within business processes. Ok, but what does that mean? Digging deeper, the keywords in that statement we need to consider are "logic" and "data".

Logic, or rules in our case, are pieces of knowledge often expressed as, "When some conditions occur, then do some tasks". Simple enough, no? These pieces of knowledge could be about any process in your organization, such as how you go about approving TPS reports, calculate interest on a loan, or how you divide workload among employees. While these processes sound complex, in reality, they're made up of a collection of simple business rules. Let's consider a daily ritual process for many workers: the morning coffee. The whole process is second nature to coffee drinkers. As they prepare for their work day, they probably don't consider the steps involved—they simply react to situations at hand. However, we can capture the process as a series of simple rules:

  • When your mug is dirty, then go clean it

  • When your mug is clean, then go check for coffee

  • When the pot is full, then pour yourself a cup and return to your desk

  • When the pot is empty, then mumble about co-workers and make some coffee

Alright, so that's logic, but what's data? Facts (our word for data) are the objects that drive the decision process for us. Given the rules from our coffee example, some facts used to drive our decisions would be the mug and the coffee pot. While we know from reading our rules what to do when the mug or pot are in a particular state, we need facts that reflect an actual state on a particular day to reason over.

In seeing how a BRMS allows us to define the business rules of a business process, we can now state some of the features of a rules engine. As stated before, we've separated logic from data—always a good thing! In our example, notice how we didn't see any detail about how to clean our mug or how to make a new batch of coffee, meaning we've also separated what to do from how to do it, thus allowing us to change procedure without altering logic. Lastly, by gathering all of our rules in one place, we've centralized our business process knowledge. This gives us an excellent facility when we need to explain a business process or transfer knowledge. It also helps to prevent tribal knowledge, or the ownership and understanding of an undocumented procedure by just one or a few users.

So when is a BRMS the right choice?

  • Consider a rules engine when a problem is too complex for traditional coding approaches. Rules can abstract away the complexity and prevent usage of fragile implementations.

  • Rules engines are also beneficial when a problem isn't fully known. More often than not, you'll find yourself iterating business methodology in order to fully understand small details involved that are second nature to users.

  • Rules are flexible and allow us to easily change what we know about a procedure to accommodate this iterative design. This same flexibility comes in handy if you find that your logic changes often over time.

  • Lastly, in providing a straightforward approach in documenting business rules, rules engines are an excellent choice if you find domain knowledge readily available, but via non-technical people who may be incapable of contributing to code.

Sounds great, so let's get started, right? Well, I promised I'd also help you decide when a rules engine is not the right choice for you. In using a rules engine, someone must translate processes into actual rules, which can be a blessing in taking business logic away from developers, but also a curse in required training. Secondly, if your logic doesn't change very often, then rules might be overkill. Likewise, If your project is small in nature and likely to be used once and forgotten, then rules probably aren't for you. However, beware of the small system that will grow in complexity going forward!

So if rules are right for you, why should you choose Drools? First and foremost, Drools has the flexibility of an open source license with the support of JBoss available. Drools also boasts five modules (to be discussed in more detail later), making their system quite extensible with domain-specific languages, graphical editing tools, web-based tools, and more. If you're partial to Eclipse, you'll also likely come to appreciate their plugin. Still not convinced? Read on and give it a shot—after all, that's why you're here, right?