Issue Details (XML | Word | Printable)

Key: MULE-60
Type: Patch submission Patch submission
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Ross Mason
Votes: 5
Watchers: 8
Operations

If you were logged in you would be able to see more operations.
Mule

JSR-94 rules engine- based router

Created: 03/Aug/04 12:05 AM   Updated: 30/Nov/08 03:21 AM  Due: 25/Jan/08
Component/s: Core: Routing / Filters
Affects Version/s: None
Fix Version/s: 2.0.0

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive drools.zip (7.94 MB)
2. Zip Archive rule-2006-08-29.zip (11 kB)

Issue Links:
Block
 

Labels:
User impact: Medium


 All   Comments   Work Log   Change History   Transitions   FishEye      Sort Order: Ascending order - Click to sort in descending order
Andrew Perepelytsya added a comment - 13/Jul/05 07:36 AM
E.g. Drools project is JSR-94 compliant, and now it has a Spring integration. We could take this shortcut in short term, just the same it was with EJBs.

Barry Kaplan added a comment - 16/Oct/05 04:23 PM
Be careful of the spring integration. Its intent was to allow for the creation of rules as pojos (and to configure drools). But with comming full RETE engine, defining rules as simple pojos with annotations (or other spring declarative mechanisms) indicating the conditions which also takes advantage of the full power of RETE is going to real hard.

I (the developer of drools-annotation and drools-spring) don't intend to try. What is need is a real DSL, similar to Jess' but more java-like. I believe that Mark has this planned.

Of course, drools could continue to be configured with spring, but this is quite simple.


Ross Mason added a comment - 25/Oct/05 04:32 PM
Thanks for the pointers Barry. Actually, (to my shame) I don't know too much about rule engines, hence why this task has been done yet

Ross Mason added a comment - 25/Oct/05 04:35 PM
Good man!

Brian Kalbfus added a comment - 08/Nov/05 04:09 PM
I've been looking into rules engines a bit lately. How would Drools be used in a inference type routing question of "Where do we route this message next?". That sounds like a backward-chaining "inference" type question, not a forward-chaining "Assertion". Drools only does forward chaining, correct? Does JSR-94 only cover forward-chaining?

Holger Hoffstaette added a comment - 05/Dec/05 05:15 AM
As someone who recently had to suffer through a class on rule reduction I might be able to help a bit here. There are essentially two types of rule engines: forward- and backward-chaining. They differ from what they try to accomplish: forward-chaining means you have an event/'fact' (i.e. 'something happened') and want to know 'what to do next'. Based on a precedence model when several rules match the fact you pick the rule that matches the fact criteria best and 'fire' it, essentially creating a new event/fact that leads to the next matching ruleset or none, in which case you have reached a conclusion. Backward-chaining works, as the name implies, backwards: you have a set of facts (prime example: symptoms for a disease) and want to know 'how did I get here?', i.e. what might have happened to make these events/facts appear. You select a set of rules that have lead to your current situation and (mostly recursively) try to reduce the ruleset backwards to the first fired rule, initiated by the first event (if it can be deduced). Doing this manually really sucks since you need to backtrack in case you have run into a branch of the ruleset tree that does not lead to the root 'cause'.
Now for event-based routing: essentially we need to decide what we want the router to decide Forward-chaining might be used for deciding what to do with an event and its associated properties (look inside the payload etc.), i.e. have a ruleset look at an event and return a new endpoint to route the event to. This means that the model endpoints would have to be encoded in the rules (high coupling). Alternatively we could create not a router but rather a transformer, creating a new event that is reinjected into the pipeline and then processed regularly. Brian calls the original forward-chaining-question "assertion" because validation is a commonly used aplication for forward-chaining, replacing nested and highly redundant if-then-else trees to arrive at a conclusion; I am not sure if this is how a rule-based router might be useful in mule since we already have filters & transformers.
Drools only supports forward-chaining and decision tables which are popular with business folks (for good reason: they are nice, simple and useful). For a nice 'high-level' (rather shallow, actually) overview of rules in SOA check out: http://www-128.ibm.com/developerworks/webservices/library/ws-soa-progmodel9/index.html
I can also offer two resources that I "happen to have" in electronic formats for purely academic reasons:
  • Business Rules and Information Systems:Aligning IT with Business Goals (Addison-Wesley, 2002)
  • Business Rules Applied - Building Better Systems Using the Business Rules Approach (Wiley & Sons, 2002)

Not sure if this was helpful in any way; if I talked nonsense someone please set me straight.


Brian Kalbfus added a comment - 05/Dec/05 12:41 PM
You talking nonsense? Nonsense! ;P From trying to follow what you're saying, it sounds like forward-chaining would suit if you got an output from an assertion. I use the term "assertion" for its core definition - that I am asserting a fact into the knowledge base or working memory (I think this is what drools calls it). I'm not sure what assertion has to do with validation in the rules domain, besides one purpose of a forward-chaining rule.
Can someone describe how drools would fit into such a router or transformer? A narrative story-like process flow is what I'd love to see here. I've only used Algernon-J, which always has a full knowledge-base (I'm using protege) available to hold rules and facts for the rules to use in their decisions. From what I read on drools, you have to assert every fact into its working memory and call a method to run all rules.
You said you have the two resources available in electronic format, can you give us the links? Thanks!

Holger Hoffstaette added a comment - 08/Aug/06 07:02 PM
setting fix-version to unknown since this won't make it for 1.3. probably needs someone to get familiar with Drools and also look how ServiceMix integrated it.

David Song added a comment - 11/Aug/06 06:06 AM
I implement my own version of drools service provider. Here is that roughly how to build:

1. make drools as service provider, so drools could use for message router or other rule message operation.
2. connector implement drools's RuleBase instance. the RuleBase contains a set of rules for this connector by property's configuration. So one connector for one set of rules.
4. endpoint's property define what kind instance to add drools's assertObject. It could create new instance by class name or instance reference .
5. endpoint's property also define which object instance use as return message payload.
5. At dispatcher's implementation for doSend,doDispach,doReceive: add message payload to drools's assertObject. It also add session, message's properties, endpointURL's properties to drools's assertObject. And then apply rules.

Drools rules will check all those assertObjects and modify them.

For rule base routing, I implement another service provider called "dynamic". Dynamic service provider get at real endpoint URI from message property. Here is the example:

add endpoint URI to message property in Component:
public Object onCall(UMOEventContext context) throws Exception
{
MuleMessage msg = new MuleMessage(obj, context.getMessage());
msg.setProperty("mqadapter_output", "jms://testqueue?connector=queuemanager");
return msg;
}

add endpoint to router and address is the URI property name:

<endpoint address="dynamic:/mqadapter_output"/>

The property also could be list. So it will send message by list of URI.

To create rule base message routing:
1. define new list instance for rdools's assertObject in rule connector.
2. add list to message property.
3. add dynamic endpoint to any router.
4. drools's rules response to add endpoints to list.


David Song added a comment - 12/Aug/06 11:40 AM
Example:

Model file:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mule-configuration PUBLIC "-//SymphonySoft //DTD mule-configuration XML V1.0//EN"
"http://www.symphonysoft.com/dtds/mule/mule-configuration.dtd">

<mule-configuration id="Logger" version="1.0">

<connector name="LoggerRuleConnector" className="org.mule.providers.rule.RuleConnector">
<properties>
<list name="rules">
<entry value="/org/mule/providers/rule/Logger.drl"/>
</list>
</properties>
</connector>

<model name="Logger">
<mule-descriptor name="Logger"
inboundEndpoint="file:///c:/temp/rule/logger/in"
implementation="org.mule.components.simple.PassThroughComponent">
<outbound-router>
<router className="org.mule.routing.outbound.ChainingRouter">
<endpoint address="rule://test" connector="LoggerRuleConnector"/>
<endpoint address="dynamic://logger_output"/>
</router>
</outbound-router>
</mule-descriptor>
</model>

</mule-configuration>

Rule file:
package org.mule.providers.rule.samples

import org.mule.umo.UMOMessage;

rule "Logger for large file"
no-loop true
when
msg : UMOMessage()
eval(getFileSize(msg) > 10)
then
msg.setProperty("logger_output", "file:///c:/temp/logger/larger?outputPattern=data.txt&outputAppend=true");
modify(msg);
end

rule "Logger for small file"
no-loop true
when
msg : UMOMessage()
eval(getFileSize(msg) <= 10)
then
msg.setProperty("logger_output", "file:///c:/temp/logger/smaller?outputPattern=data.txt&outputAppend=true");
modify(msg);
end

function long getFileSize(UMOMessage msg)
{
byte bytes[] = (byte[])msg.getPayload();
return bytes.length;
}


David Song added a comment - 14/Aug/06 12:41 PM
Create JSR-94 version of rule service provider. Attach is the source file.

Well known issue:
1. it does not support receive endpoint.
2. It does not Object filter.
3. It only tests on Drools

There are two example:
1. RuleHello: demo how to use rule for message processing.
2. RuleBaseRounting: demo how to use rule do message rounting. It depends on another feature: "Dynamic service provider". I will request it and post that source codes later


David Song added a comment - 14/Aug/06 12:42 PM
Souce codes for JSR-94 implementation

David Song added a comment - 14/Aug/06 02:01 PM
Dynamic service provider is at: http://jira.symphonysoft.com/browse/MULE-970

David Song added a comment - 29/Aug/06 07:36 PM
Send new implementation of rule provider, it shoud fix some bug for previous version and make test case

Andrew Perepelytsya added a comment - 29/Aug/06 07:43 PM
Deleted an older attachment.

Ross Mason added a comment - 05/Oct/06 12:30 PM

Ross Mason added a comment - 05/Oct/06 12:31 PM
Hi David,

Thanks for the submission. We're going to start looking at this for the next release.

Cheers,

Ross


Ross Mason added a comment - 09/Oct/06 02:48 PM
Hi David,

I've just started importing this. The dependency info is not with the zip. Can you confirm the Jar required. I'm using

drools-3.0.4
drools-jsr94-3.0.4

It also need this dependency -
<dependency>
<groupId>org.jcp</groupId>
<artifactId>jsr94</artifactId>
<version>1.1</version>
</dependency>

I can't find this anywhere, is it in a maven repo somehere, eclse could please attach it.

Same for -

org.apache.jakarta.commons:commons-jci-core:jar:1.0-406301

Thanks,

Ross


David Song added a comment - 09/Oct/06 03:44 PM
Hi Ross,

For compile, it only needs jsr94-1.1.jar since it does not implement as drools specific.

If you want to run test program: org.mule.test.usecases.providers.rule.RuleSampleTestCase with drools, it needs:
drools-compiler-3.0.4.jar
drools-core-3.0.4.jar
drools-jsr94-3.0.4.jar

With third party library:
antlr-2.7.6.jar
antlr-3.0ea8.jar
commons-jci-core-1.0-406301.jar
commons-jci-eclipse-3.2.0.666.jar
commons-lang-2.1.jar
stringtemplate-2.3b6.jar
xstream-1.1.3.jar

Following libraries are shipped by drools but already in Mule:
commons-collections-3.1.jar
commons-io-1.1.jar
commons--logging-api-1.0.4.jar
jxl-2.4.2.jar
junit-3.8.1.jar
xercesImpl-2.6.2.jar
xml-apis-1.0.b2.jar

Following libraries does not need for test program. It uses for other drools feature like supporting XML rule file, Decision tree.
drools-decisiontables-3.0.4.jar
colt-1.2.0.jar
commons-jci-janino-2.4.3.jar
concurrent-1.3.4.jar
core-3.2.0.666.jar
janino-2.4.3.jar
jung-1.7.2.jar
xpp3-1.1.3.4.O.jar

You can get those files from:
http://labs.jboss.com/portal/jbossrules/downloads

You also need change code in method getRuleInputStream():

from:
return FileUtils.loadResource(fileName, getClass());
to
return new FileInputStream(FileUtils.getResourcePath(fileName, getClass()));

since FileUtils method rename in 1.3.

David Song


David Song added a comment - 09/Oct/06 03:48 PM
Hi Ross,

To easy get start with drools, you don't have to do any additional setting and just run org.mule.test.usecases.providers.rule.RuleSampleTestCase, see attach file's comment.

David Song


Ross Mason added a comment - 09/Oct/06 06:35 PM
Thanks David. The transport is now available under http://svn.codehaus.org/mule-contrib/transports/jsr94-rules.

You should committer access to this repo and can build the module using

mvn install


Travis Carlson added a comment - 18/Oct/06 08:59 AM
Alex Kozlenkov has offerred to contribute his work on using the Prova Rule Engine with Mule
http://www.nabble.com/Agents-in-Prova-rule-language-wrapped-by-UMO-tf2448257.html

Alex Kozlenkov added a comment - 30/Oct/06 09:44 AM
Hi guys,

I have uploaded the promised example demostrating the use of Prova and Drools agents on the bus.

Here is a short write-up with a more detailed one to follow.

The key components ProvaUMOImpl.java and DroolsUMOImpl.java are used for sending and (for Prova agents) receiving messages.

There are three parallel conversations ongoing at the same time.

(1) Agent001 sends tow messages to Agent002;
(2) Drools agent notifies Agent002 about a state change;
(3) A more complex scatter-gather protocol for a Manager and two Worker's. The actual code for Worker's is uploaded to the Worker's by the Manager in a mobile-agent fashion.

There is only one rulebase behind each UMO descriptor, which means that if Mule creates several instances, the access from them to the rulebase happens in parallel and in the case of a conversation protocol, should be executed in lock-step. Imagine that an agent expect messages A and then B. If B arrives first due to the thread parallelism, the agent will be in an incorrect state. Lock-step execution always exchanges messages in pairs, i.e., an ack is sent for each message, and then the other side continues.

The formalism behind the agents is based on pi-calculus. It allows for sending and receiving messages in the rule bodies as well as sending agent addresses and conversation-id's as part of each message.

The project uses both Maven 2 and a Maven 2 plugin for Eclipse so it can be run from both.

The examples requires Prova 2.0 Beta 3 that is included in the local Maven repository.

Alex Kozlenkov
Advanced Technology Group
Betfair Ltd.


Ross Mason added a comment - 18/Sep/07 03:46 AM
There is now a MuleForge project that hosts these patches: http://www.mulesource.org/display/DROOLS/Home, code is here: http://svn.muleforge.org/mule-transport-drools/trunk/
We will include this functionality in the Mule distribution sometime after 2.0 (hence we've flagged it a 3.0 for now)

Alex, looking at the forge project you should be listed as despot as well. If you sign up on the forge I will get someone to add you to the project. There are currently no artifacts because one of the tests fail.


Ross Mason added a comment - 31/Dec/07 10:33 AM
Isn'y this on the MuleForge: http://www.mulesource.org/jira/browse/DROOLS ?

Ross Mason added a comment - 30/Nov/08 03:21 AM
on MuleForge