Book Image

Mastering JBoss Drools 6

By : Mariano De Maio, Mauricio Salatino, Esteban Aliverti
Book Image

Mastering JBoss Drools 6

By: Mariano De Maio, Mauricio Salatino, Esteban Aliverti

Overview of this book

Mastering JBoss Drools 6 will provide you with the knowledge to develop applications involving complex scenarios. You will learn how to use KIE modules to create and execute Business Rules, and how the PHREAK algorithm internally works to drive the Rule Engine decisions. This book will also cover the relationship between Drools and jBPM, which allows you to enrich your applications by using Business Processes. You will be briefly introduced to the concept of complex event processing (Drools CEP) where you will learn how to aggregate and correlate your data based on temporal conditions. You will also learn how to define rules using domain-specific languages, such as spreadsheets, database entries, PMML, and more. Towards the end, this book will take you through the integration of Drools with the Spring and Camel frameworks for more complex applications.
Table of Contents (18 chapters)
Mastering JBoss Drools 6
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Mastering JBoss Drools 6 was written to provide a comprehensive guide that helps you understand the main principles used by the Drools project to build smarter applications, using the power of business rules. This book covers important topics such as the drools rule syntax, Drools runtime configurations, internal mechanisms of the rule engine, and different ways of writing rules using domain-specific languages, integration patterns, and tooling descriptions. All these topics are covered with a technical perspective that will help developers adopt these technologies. The book is also targeted at topics that are not always covered by business rule systems, such as business processes, complex event processing, and tooling extension capabilities that are introduced to demonstrate the power of mixing different business knowledge descriptions into one smarter, adaptive platform.

What this book covers

Chapter 1, Rules Declarative Nature, talks about what the reader will need to understand about rules to apply them to a project of their own. In short, it will cover the main structure of rules and why said structure is so useful for solving complex problems, along with some of the problems usually solved using rules. Also, we'll explain how rules adjust within the development life cycle.

Chapter 2, Writing and Executing Rules, concentrates on creating a project with rules defined in a simple text file in order to understand both the basic components of rules and all the parts involved in a Drools rule project. This chapter also covers the basics of installing the necessary libraries to work with Drools in a project.

Chapter 3, Drools Runtime, concentrates on the KIE modules (Knowledge Is Everything modules) that are needed to create a rule environment and how to use them to create a rule runtime. All the different ways of creating a runtime for rules are introduced in this chapter.

Chapter 4, Improving Our Rule Syntax, teaches the concepts we need to understand the basic technical syntax used to define Business Rules in Drools. This chapter concentrates on learning about rule attributes, such as salience, lock-on-active, agenda-groups, and so on, which give a lot more control over which rules are to be fired and when. Also, we'll learn about the from clause of rules, which allows for different sources of data for evaluating our rule conditions.

Chapter 5, Understanding KIE Sessions, starts with an introduction to the different types of session supported by Drools. It then covers many of the different components that can be added to the session to make it register, alter, or change our rules execution, such as global variables, channels, event listeners, operators, and accumulate functions.

Chapter 6, Complex Event Processing, gives a brief introduction to the Complex Event Processing (CEP) concept and how Drools allows us to work with complex events. It covers features such as events, type declarations, temporal operators, sliding windows, and other components of Drools for detecting and managing complex events.

Chapter 7, Human Readable Rules, explains human readable ways to define our rules, such as Domain Specific Language (DSL), Decision Tables, and Templates. They allow the user to create a mapping between the rule language (highly technical) and the specific language that domain experts can easily understand. These mappings will allow business users to be able to define and modify rules without much knowledge of the technical aspects of Drools.

Chapter 8, Rules Testing and Troubleshooting, explains what the different challenges of testing Drools' rules are. It gives an overview of the possible errors and problematic scenarios we may find when testing our application. A set of good practices and techniques to identify and mitigate these problems is also provided in this chapter.

Chapter 9, Introduction to PHREAK, is an introduction to the underlying algorithm Drools uses for the evaluation of business rule assets. It provides an overview of how a Knowledge Base is converted into a PHREAK network composed of specialized nodes that perform different kinds of task, such as classification, constraint evaluation, and join operations. This chapter provides concrete examples on how rules are compiled and evaluated, covering some of the most used patterns and operators in PHREAK.

Chapter 10, Integrating Rules and Processes, goes into detail about the workflow aspect of rules. Specifically, it covers how rules can invoke processes and vice versa. In this chapter, we will also cover the aspects required for implementing a persistent Kie Session, to be used (and reused) both for Rules and for Processes execution.

Chapter 11, Integrating Drools with our Apps, shows integration with the Spring and Camel frameworks, in order to integrate Drools in more complex applications. It also shows us how to make changes to our rules while the application runs and how to make services to invoke rules remotely, using a component called Kie Execution Server.

What you need for this book

This is a developer guide, so the thing you will find most useful when you read this book is a computer beside you, where you can try the examples and open, compile, and test the provided projects. The main idea behind the book is to get you up to speed in the development of applications or tooling that use Drools 6 and for this reason the book spends a lot of time with code examples and unit tests to run. Good programming skills are required to easily understand the examples presented in this book. Most of the chapters complement the covered topics with a set of executable Maven projects. A basic understanding of Maven, Java, and JUnit is required.

Who this book is for

This book is for Java developers and architects who need to have a deep understanding of how Business Rule frameworks behave in real-life implementations. The book assumes that you know the Java language well and also have experience with some widely used frameworks, such as Hibernate. You should also know the basics of relational databases and Maven-based applications.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the import directive."

A block of code is set as follows:

rule "Classify Item - Low price"
    when
        $i: Item(cost < 10.00)
    then
        insert(new IsLowRangeItem($i));
end

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

rule "Classify Item - Low price"
    when
        $i: Item(cost < 10.00)
    then
        insert(new IsLowRangeItem($i));
end

Any command-line input or output is written as follows:

# mvn -B archetype:generate
     -DarchetypeGroupId=org.apache.maven.archetypes-DgroupId=org.drools.devguide-DartifactId=myfirst-drools-project

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.