Announcement Announcement Module
Collapse
No announcement yet.
Drools Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drools Integration

    Just started looking at Spring Integration and it looks really excellent. It strikes me that it could be quite complementary to use the Drools rules engine in a Spring Integration application. Lots of ESB type tools have built in rules engines and BPEL or BPMN engines, and Drools can provide this.

    I had a go at writing an endpoint adapter which I've attached to this post. It provides two alternative service activators:
    - addFact. This asserts the incoming message as a fact in the rules engine, as defined in Drools Expert. I wondered whether to add the payload (allowing efficient class-based constraints) or the message (giving access to headers) and ended up adding both (they can be joined in a rule). This could for example allow much more complex aggregation rules.
    - signalEvent. This fires the message as a signal into the rules engine, which can be configured to start a business process (e.g. BPMN), as defined in Drools Flow. The business processes in turn trigger rules as they progress.

    Drools has a new concept of "channels" to get facts or other information out of the rules engine, and it's easy to map these onto Spring Integration channels. Drools also provides a schema for configuring the rules engine within a Spring configuration file, which should be used with this adapter (URL is in the attached file). For example, you can configure the rules engine as an event-cloud (Drools Fusion), which could be particularly useful with Spring Integration, as it can manage message expiry, and calculate averages or totals extracted from messages over a time range.

  • #2
    Thanks for a feedback. Yet another proof of how simple it is to use SI to integrate with other systems - Drools in this case.

    On the related note
    . . .as it can manage message expiry, and calculate averages or totals extracted from messages over a time range. . .
    Have you looked at Spring Integration JMX support? It does all that today.

    Comment


    • #3
      Spring Integration JMX support reports statistics on the flow of messages, using rules (e.g. decay) fixed in the framework. Using Drools Fusion could allow reporting of statistics on the contents of the payloads, using configurable business-specific rules.

      Comment


      • #4
        You might want to have a look at the Activiti support that we have currently in our sandbox repository. We'll be polishing that and evolving toward a GA release over the next few months. For the BPMN process functionality, it should be very similar. As far as *inbound* adapters go, have a look at MessageProducerSupport (for one-way) and MessagingGatewaySupport (for request/reply). Those provide the easiest way to focus on whatever is necessary to receive from some other system/framework/API and then push Messages into Spring Integration without having to worry about much more than calling a send() method.

        Looking forward to seeing the project evolve.
        -Mark

        Comment


        • #5
          Drools is a fantastic rules engine, and I too would encourage you to continue evolving it - we're here when you need support. If you're just getting into the code, of course, Mark's suggestions are very appropriate and the SI source code itself is very illustrative.

          That said, as Mark pointed out, there is some overlap already since the latest generation of Drools purports to do so much: BPMN, CEP, Rules, governance, etc
          - the Spring Integration Activiti module supports BPMN 2 workflow scenarios
          - an open-source, third party contribution by a company (OpenCredo - see http://www.jonaspartner.com/?p=335 this blog here for some samples) supports using the Esper Complex Event Processsing engnie with Spring Integration. IIRC, that was Spring Integration 1.0-based, not 2. I haven't realy followed up there, but it could probably be made to work with SI 2.

          Perhaps these projects can influence your approach. Either way, good rules engine support is certainly important. One possible approach is a Rules engine-based router component for Spring integration that works the same way that Drools works in conjunction with he Drools Flow component to handle conditionals / routing. good luck

          Comment


          • #6
            Drools Integration with Spring

            Hi Experts,

            I am facing one issue while integrating drools with Spring.

            I have done the following configurations

            Beans.xml :

            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:drools="http://drools.org/schema/drools-spring"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
            xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schem...-beans-2.5.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schem...ontext-2.5.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schem...ng-aop-2.0.xsd
            http://www.directwebremoting.org/schema/spring-dwr
            http://www.directwebremoting.org/sch...ng-dwr-2.0.xsd
            http://drools.org/schema/drools-spring http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd">

            <bean id="droolsDAOImpl" class="com.dao.DroolsDAOImpl">
            <property name="sessionFactory" ref="mySessionFactory" />
            <property name="ksession" ref="ksession" />
            <property name="intermediateData" ref="intermediateData" />
            <property name="kbase" ref="kbase" />
            </bean>

            <bean id="intermediateData" class="com.pojo.IntermediateData" />

            <drools:kbase id="kbase">
            <drools:resources>
            <drools:resource type="DRL" source="classpath:Sample.drl"></drools:resource>
            </drools:resources>

            </drools:kbase>

            <drools:ksession id="ksession" type="stateful" kbase="kbase"/>

            ----------------------------------------------------------------------------------------------------
            DroolsDAOImpl.java :


            public class DroolsDAOImpl implements DroolsDAO {

            private StatefulKnowledgeSession ksession;

            private IntermediateData intermediateData;

            private KnowledgeBase kbase;

            public KnowledgeBase getKbase() {
            return kbase;
            }

            public void setKbase(KnowledgeBase kbase) {
            this.kbase = kbase;
            }

            public StatefulKnowledgeSession getKsession() {
            return ksession;
            }

            public void setKsession(StatefulKnowledgeSession ksession) {
            this.ksession = ksession;
            }

            public static void main(String args[]) throws Exception{

            Resource res = new ClassPathResource("beans.xml");
            BeanFactory factory = new XmlBeanFactory(res);
            DroolsDAOImpl droolsDAOImpl=(DroolsDAOImpl)factory.getBean("droo lsDAOImpl");
            droolsDAOImpl.init_drools();

            }

            public void init_drools() throws Exception{


            try {


            ksession = kbase.newStatefulKnowledgeSession();


            intermediateData.setNoofPay(noofPaytemp());
            intermediateData.setRegPay(regpaytemp());

            ksession.insert(intermediateData);
            ksession.fireAllRules();

            } catch (Throwable t) {

            logger.error("Exception occured in DroolsDAOImpl---"+t);
            throw new Exception("Some Error Occured. Please try after some time");

            } }


            I am having one drl file : Sample.drl which contains rule and IntermediateData is simple pojo.
            But after running this I am getting following error:

            Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'drools:kbase'.

            Can anyone help me with this issue? Thanks in advance

            Comment


            • #7
              Hi,

              It might due to two reason,

              1)Not able to identify the tag 'drools:kbase', please copy this configuration file in notepad and save as xml format and try it. Some times we open the file in Word pad and character gets misplaced and then while reading through SAX parser not able identify the tag.
              2)Mismatch of name space version, please use the correct version of the name space xsd and may your problem resolve.

              Regards,
              Pankaj

              Comment


              • #8
                Hi, I've just had the same problem.

                The reason of the error is that http://anonsvn.jboss.org/repos/labs/...ring-1.0.0.xsd has suddenly become unavailable

                I updated my applicationContext.xml changing this address by : http://drools.org/schema/drools-spring.xsd
                So now, my schema is loaded from drools-spring.jar. I do not depend on any external resource.

                By the way, thank you very much for the code you provided, it helped me integrate Drools.

                Comment


                • #9
                  org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: ...

                  Thanks masterchaf for the drools-spring schema note!

                  xmlns:drools="http://drools.org/schema/drools-spring"
                  ...
                  xsi:schemaLocation="
                  http://drools.org/schema/drools-spring
                  http://drools.org/schema/drools-spring.xsd">

                  This is the correct configuration. I was getting "org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: ..." errors as well.

                  Comment


                  • #10
                    drools grid

                    excelent work. too bad dependency on drools-grid-impl and sub dependencies like apache mina and hibernate rendered unusable to our projects. is there a way to get rid of this dependency?

                    Comment


                    • #11
                      ibw,

                      Do you have a complete application using this endpoint? I'm wondering how you have all the drools configured.

                      Thanks

                      Zach

                      Comment


                      • #12
                        Hi,
                        I was facing the same problem "org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: ..." when I was using http://anonsvn.jboss.org/repos/labs/...ring-1.0.0.xsd.


                        When I changed my configuration to this:
                        xmlns:drools="http://drools.org/schema/drools-spring"
                        ...
                        xsi:schemaLocation="
                        http://drools.org/schema/drools-spring
                        http://drools.org/schema/drools-spring.xsd">

                        I am getting error in application-context.xml at complie time only something like this:

                        "Referenced file contains error(http://drools.org/schema/drools-spring.xsd)..."


                        Moreover when I type this url:"http://drools.org/schema/drools-spring.xsd" in my browser it redirects me to jboss-drools home page.The xsd does not come.

                        Does anybody have any idea whats happenning?
                        Can anybody help please....

                        Comment

                        Working...
                        X