Contents
This topic describes how to run the Drools sample application, which illustrates how to use the TIBCO StreamBase® Operator for Drools to integrate a business rule interpreted by the Drools Core rules engine. For more information about this sample, including information about optionally integrating the Drools Core plug-in with StreamBase Studio, see Using the Drools Operator.
Note
The Java code in this sample is delivered only in source code form. To build the code, you must load the sample into StreamBase Studio, which automatically builds the Java code.
This sample implements a simplified Order Routing-like application, one whose sole logic is to determine whether or not an
order can be routed by a downstream Smart Order Routing system, depending on the volume of the order being managed. The implementation
of the routing decision is embedded in the Drools rules file, routable-order.drl.
Note
When a StreamBase field has mixed case (such as MyField), you must refer to that field in your rules file with the first letter in lowercase (myField). Otherwise, you may see errors such as "Unable to create Field Extractor for "MyField".
This sample has the following files:
-
The sample EventFlow application,
rulesuser.sbapp. -
A Drools rule file,
routable-order.drl. It contains a single rule that modifies theRoutableboolean field tofalseif the tuple contains a fieldVolumewhose value is greater than 1,000. -
In the
java-srcdirectory, a Java interface file,IOrder.java, that describes the relevant portion of tuples entering the Drools operator.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer, double-click to open the
rulesuser.sbappapplication. -
Make sure the application is the currently active tab in the EventFlow Editor, then click the
Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
ParentOrderinput stream. -
Enter any
SymbolandPrice, and enter aVolumethat is less than 1,000.Click , and observe that the output stream that received the data is the
RoutableParentOrderstream, with a value oftruefor theRoutablefield. -
Modify the
Volumefield to a value that is greater than 1,000.Click , and observe that the output stream that received a new tuple is the
NonRoutableParentOrderstream, with a value offalsefor theRoutablefield. -
When done, press F9 or click the
Stop Running Application button.
This section describes how to run this sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.
-
In StreamBase Studio, create a bundle file for this sample's application:
-
In the Package Explorer, right-click and select Export from the context menu.
-
In the Export dialog, select → and click .
-
On the next panel, open the
sample_droolsproject folder and selectrulesuser.sbapp. -
On the same panel, specify a path and file name for the bundle file, then click . For example, create a bundle file with the following path name:
c:\tmp\rulesuser.sbbundleor/home/.sbuser/tmp/rulesuser.sbbundle
-
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows.
-
In window 1, navigate to the directory location where you saved your bundle file, then start StreamBase Server with the bundle file as its argument. For example:
Windows: cd /d c:\tmp sbd rulesuser.sbbundleLinux: cd /home/
sbuser/tmp sbd ./rulesuser.sbbundle -
In window 2, type:
sbc dequeueThis window will display tuples dequeued from the application's output ports.
-
In window 3, type:
sbc enq ParentOrderThis window is now ready to accept tuples typed with CSV syntax.
-
In window 3, type:
IBM, 400, 176.48 -
Observe in window 2 one tuple is emitted on the RoutableParentOrder stream, and its
Routablefield is markedtrue:RoutableParentOrder,IBM,400,176.48,true -
In window 3, type:
DELL, 1500, 17.15 -
Observe in window 2 that one tuple is emitted on the NotRoutableParentOrder stream, and its
Routablefield is markedfalse:NotRoutableParentOrder,DELL,1500,17.15,false -
In window 2, type Ctrl+C to terminate the dequeuer. Then type the following command to shut down the server:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select → .
-
Select
droolsfrom the Extending StreamBase category. -
Click OK.
StreamBase Studio creates a project for the Drools sample in your current Studio workspace.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
studio-workspace/sample_droolsSee Default Installation Directories for the location of studio-workspace on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir/sample/droolsSee Default Installation Directories for the default location of studio-workspace on your system.
