Drools Tools Reference Guide
This guide is for developers
Chapter 1. Preface
1.1. Business Integration
1.2. What is a Service-Oriented Architecture?
A Service Oriented Architecture (SOA) is not a single program or technology. Think of it, rather, as a software design paradigm.
1.3. Key Points of a Service-Oriented Architecture
- the messages being exchanged
- the agents that act as service requesters and providers
- the shared transport mechanisms that allow the messages to flow back and forth.
1.4. What is the JBoss Enterprise SOA Platform?
1.5. The Service-Oriented Architecture Paradigm
- Service Provider
- A service provider allows access to services, creates a description of a service and publishes it to the service broker.
- Service Requester
- A service requester is responsible for discovering a service by searching through the service descriptions given by the service broker. A requester is also responsible for binding to services provided by the service provider.
- Service Broker
- A service broker hosts a registry of service descriptions. It is responsible for linking a requester to a service provider.
1.6. Core and Components
1.7. Components of the JBoss Enterprise SOA Platform
- A full Java EE-compliant application server (the JBoss Enterprise Application Platform)
- an enterprise service bus (JBoss ESB)
- a business process management system (jBPM)
- a business rules engine (JBoss Rules)
- support for the optional JBoss Enterprise Data Services (EDS) product.
1.8. JBoss Enterprise SOA Platform Features
- The JBoss Enterprise Service Bus (ESB)
- The ESB sends messages between services and transforms them so that they can be processed by different types of systems.
- Business Process Execution Language (BPEL)
- You can use web services to orchestrate business rules using this language. It is included with SOA for the simple execution of business process instructions.
- Java Universal Description, Discovery and Integration (jUDDI)
- This is the default service registry in SOA. It is where all the information pertaining to services on the ESB are stored.
- This transformation engine can be used in conjunction with SOA to process messages. It can also be used to split messages and send them to the correct destination.
- JBoss Rules
- This is the rules engine that is packaged with SOA. It can infer data from the messages it receives to determine which actions need to be performed.
1.9. Features of the JBoss Enterprise SOA Platform's JBossESB Component
- Multiple transports and protocols
- A listener-action model (so that you can loosely-couple services together)
- Content-based routing (through the JBoss Rules engine, XPath, Regex and Smooks)
- Integration with the JBoss Business Process Manager (jBPM) in order to provide service orchestration functionality
- Integration with JBoss Rules in order to provide business rules development functionality.
- Integration with a BPEL engine.
- Be configured to work with a wide variety of transport mechanisms (such as e-mail and JMS),
- Be used as a general-purpose object repository,
- Allow you to implement pluggable data transformation mechanisms,
- Support logging of interactions.
org.jboss.soa.esb. Use the contents of the
org.jboss.internal.soa.esbpackage sparingly because they are subject to change without notice. By contrast, everything within the
org.jboss.soa.esbpackage is covered by Red Hat's deprecation policy.
1.10. Task Management
1.11. Integration Use Case
1.12. Utilising the JBoss Enterprise SOA Platform in a Business Environment
Chapter 2. Introduction
2.1. Intended Audience
2.2. Aim of the Guide
Chapter 3. Creating a New Drools Project
3.1. Creating a Sample Drools Project
- To create a new Drools project, click New Drools Project wizard.→ → → → . This will open theType the project name into the relevant field and click thebutton.
- You will see a list of default artifacts to it like sample rules, decision tables or ruleflows and Java classes for them. Add the ones that are relevant to your project and click.
- You will be asked to specify a Drools runtime. If you have not yet set it up, you should do this now by clicking thelink.You should see the Preferences window where you can configure the workspace settings for Drools runtimes. To create a new runtime, click the button. It will prompt you to enter a name for a new runtime and a path to the Drools runtime on your file system.
NoteA Drools runtime is a collection of .jars on your file system that represent one specific release of the Drools project .jars. When creating a new runtime, you must either point to the release of your choice or create a new runtime on your file system from the .jars included in the Drools Eclipse plugin.
- You can create a new Drools 5 runtime from the .jars embedded in the Drools Eclipse plugin. Click thebutton, select the folder where you want the runtime to be created and click .
- You will see the newly created runtime show up in your list of Drools runtimes. Check it and click thebutton.
- Click theto complete the project creation.
- Now you have a basic structure, classpath, sample rules and test case to get you started.
3.2. Drools Project Structure Overview
src/main/rulesdirectory and an example java file
DroolsTest.java. These can be used to execute the rules in a Drools engine in the folder
src/main/java, in the
com.samplepackage. All the others .jar's that are necessary during execution are also added to the classpath in a custom classpath container called Drools Library .
3.3. Creating a New Rule
- To create a new project you can either create an empty text
.drlfile or utilize the New Rule Package wizard.
- To open the wizard select→ → or use the menu with the JBoss Drools icon on the toolbar.
- On the wizard page, select rules as a top level directory to store your rules and enter a rule name. Next, specify the mandatory rule package name. This defines a namespace that groups rules together.
- The wizard then generates a rule skeleton to get you started.
Chapter 4. Debugging Rules
4.2. Creating Breakpoints
- To create breakpoints in the Package Explorer view or Navigator view of the Drools perspective, double-click the selected
.drlfile to open it in the editor.
- You can add and remove rule breakpoints in the
.drlfiles in two ways:
- Double-click the rule in the Rule editor at the line where you want to add a breakpoint. A breakpoint can be removed by double-clicking the rule once more.
NoteNote that rule breakpoints can only be created in the consequence of a rule. Double-clicking on a line where no breakpoint is allowed will do nothing.
- Right-click the ruler. Select theaction in the context menu. Choosing this action will add a breakpoint at the selected line or remove it if there is one already.
- The Debug perspective contains a Breakpoints view which can be used to see all defined breakpoints, get their properties, enable/disable and remove them. You can switch to it by clicking → → → .
- Drools breakpoints are only enabled if you debug your application as a Drools Application. To do this you should perform one of two actions:
- Select the main class of your application. Right-click on it and select→ .
- Alternatively, select→ to open a new dialog window for creating, managing and running debug configurations.Select the Drools Application item in the left tree and click the button (leftmost icon in the toolbar above the tree). This will create a new configuration with a number of the properties already filled in based on main class you selected in the beginning. All properties shown here are the same as any standard Java program.
NoteRemember to change the name of your debug configuration to something meaningful.
- Click thebutton on the bottom to start debugging your application.
- After enabling the debugging, the application starts executing and will halt if any breakpoint is encountered. This can be a Drools rule breakpoint, or any other standard Java breakpoint. Whenever a Drools rule breakpoint is encountered, the corresponding
.drlfile is opened and the active line is highlighted. The Variables view also contains all rule parameters and their value. You can then use the default Java debug actions to decide what to do next (resume, terminate, step over, etc). The debug views can also be used to determine the contents of the working memory and agenda at that time as well (the current executing working memory is automatically shown).
Chapter 5. Editors
5.2. DSL Editor
- In Drools, the DSL configuration is stored in
.dslfiles. These can be created selecting → → → → from the projects context menu.
Figure 5.1. The DSL editor
5.3. DSL Editor Components
Table 5.1. DSL Editor Components
|Description||User's comments on a certain language message mapping.|
|Table of language message mappings|| The table is divided into 4 rows:
By clicking on some row's header you can sort the lines in the table according to the clicked row. By double clicking on the line the Edit language mapping wizard will be open.
|Expression||Shows the language expression of the selected table line (language message mapping).|
|Mapping||Shows the rule of language mapping for the selected table line (language message mapping).|
|Object||Shows the object for the selected table line (language message mapping).|
|Sort By||This option allows you to change the sorting order of the language message mappings. To do this select from the drop down list the method of sorting you want and click thebutton.|
5.4. Edit the Language Mapping Wizard
- This wizard can be opened by double clicking some line in the table of language message mappings or by clicking thebutton. You can edit the language expressions, rule mapping, objects and scopes of instance.
Figure 5.2. Editing options
- To change the mapping a user should edit the appropriate options and finally click thebutton.
5.5. Add a Language Mapping Wizard
Procedure 5.1. Task
- Click on thebutton and a dialog box will appear.
- Enter the details of your language mapping wizard into the relevant fields.
Figure 5.3. Dialog box
5.6. Drools Flow Editor
- Ruleflows can only be set by using the graphical flow editor which is part of the Drools plugin for Eclipse. Once you have set up a Drools project, you can start adding ruleflows. Add a ruleflow file (.rf) by clicking on the project and selecting→ → → .By default these ruleflow files (.rf) are opened in the graphical Flow editor.
- The Flow editor consists of a palette, a canvas and an outline view. Select the element you would like to create in the palette and then add it to the canvas by clicking on the preferred location.
- Clicking on the Select option in the palette and then on the element in your ruleflow allows you to view and set the properties of that element in the Properties view.
- The Outline view is useful for complex schemata where not all nodes are seen at one time. Using the Outline view allows you to easily navigate between parts of a schema.
5.7. Different Types of Control Elements in Flow Palette
Table 5.2. Different Types of Control Elements in Flow Palette
| ||Select||Select a node on the canvas.|
| ||Marquee||Selects a group of elements.|
| ||Sequence flow||Joins two elements on the canvas|
5.8. Different Types of Nodes in Flow Palette
Table 5.3. Different Types of Nodes in Flow Palette
| ||Start Event||The start of the ruleflow. There can only have one start node. The Start Event cannot have incoming connections and should have one outgoing connection. Whenever the ruleflow process is started, the execution is started here and is automatically forwarded to the first node linked to this Start Event.|
| ||End Event||A ruleflow file can have multiple End Events. This node should have one incoming connection and no outgoing connections. When an end node is reached in the ruleflow, the ruleflow is terminated (including other remaining active nodes when parallelism is used).|
| ||Rule Task||Represents a set of rules. A Rule Task node should have one incoming connection and one outgoing connection. The RuleFlowGroup property is used to specify the name of the ruleflow-group representing the set of rules. When a Rule Task node is reached in the ruleflow, the engine will start executing rules that are part of the corresponding ruleflow-group. Execution automatically continues to the next node when there are no more active rules in this ruleflow-group.|
| ||Gateway[diverge]||Allows you to create branches in your ruleflow. A Gateway[diverge] node should have one incoming connection and two or more outgoing connections.|
| ||Gateway[converge]||Allows you to synchronize multiple branches. A Gateway[converge] node should have two or more incoming connections and one outgoing connection.|
| ||Reusable Sub-Process||Represents the invocation of another ruleflow from this ruleflow. A subflow node should have one incoming connection and one outgoing connection. It contains the property processId which specifies the ID of the process that should be executed. When a Reusable Sub-Process node is reached in the ruleflow, the engine will start the process with the given ID. The subflow node will only continue if the other subflow process has terminated its execution. The subflow process is started as an independent process, which means that the subflow process will not be terminated if this process reaches an end node.|
| ||Script Task||Represents an action that should be executed in this ruleflow. A Script Task node should have one incoming connection and one outgoing connection. It contains the property "action" which specifies the action that should be executed. When a Script Task node is reached in the ruleflow, it will execute the action and continue with the next node. An action should be specified as a piece of (valid) MVEL code.|
5.9. Rule Editor
.rulein the case of spreading rules across multiple rule files) extension. The editor follows the pattern of a normal text editor in Eclipse, with all the normal features of a text editor.
5.10. Content Assist
Ctrl+Space. Content Assist shows all possible keywords for the current cursor position. It also suggests all available fields in a message.
5.11. Code Folding
5.12. Synchronization with Outline View
5.13. Rete Tree View
.drlfile. Just click on the Rete Tree tab at the bottom of the Rule editor. Afterwards you can generate the current Rete Network visualization. You can push and pull the nodes to arrange your optimal network overview.
Appendix A. Revision History
|Revision 5.3.1-68||Wed Feb 20 2013|