8 Replies Latest reply on Nov 3, 2014 1:59 PM by jesstei

    Using Drools within an Java  Enterprise Application

    jesstei

      Hello,

       

      I would like to build an architecture that fullfils the following requirements:

      • Receives messages from multiple senders.
      • Sender implementations are done in different programming languages (C, python, ....)
      • Messages are classified during reception. Classification criteria is a message type and time relationship between reception of these messages
      • Messages can initiate an action e.g. change a configuration file
      • Messages turn into notification and are distributed to multiple consumers
      • High volume of messages
      • Messages happen asynchronously

       

      I am using Java JDK 1.8.0_20 and Wildfly 8.1.0_Final. I thought to go for JMS and Drools. Therefore I built an Java ear File.

      Within this ear. file I developed a MDB that receives messages via STOMP in an JMS Queue. The messages are normalized within an Stateless Session Bean and should now send to the rules engine (Drools) to perform classification and identifiy time relationship.

       

      At this point  I am struggling how to integrate Drools into Wildfly 8.1.0.. I already set up a Drools Project and were able to run a simple Drools Application that classified  a message based on a type and print out something on the console. But this small example was a standalone application and not used within an ear file. After some search I found KIE-wb-distribution-wildfly8.war. But I fail to deploy it on wildfly.

       

      Where do I find a tutorial or description how to integrate Drools into an Java Enterprise Application? How would you build this architecture if it is not possible to make use of Drools within Wildfly? Maybe I could skip JMS completly because Drools also fullfils the requirement to receive messages from different senders.....

       

      Any help would be appreciated.

      Kind regards,

      jesstei

        • 1. Re: Using Drools within an Java  Enterprise Application
          psiroky

          Hi,

           

          it is kind of simplification, but Drools (meaning just the core rule engine) is "just" a Java library and can be used/embedded into your application basically as easily as any other set of third party jars. As you mentioned, you already have the standalone Drools application. It should be fairly easy then to just add the logic into the MDB and embed the Drools libraries in the EAR/WAR.

           

          There also some advanced advanced features like CDI integration that could be useful in this case. See Chapter 10. CDI or drools/drools-examples-cdi/cdi-example at master · droolsjbpm/drools · GitHub for more information.

           

          You could also create the Drools runtime as a separate application (or use the currently developed kie-server) and use remote APIs (like REST) to interact with the engine. But from your description, it seems embedding the engine is a better choice.

           

          Since you are asking in BPM Suite forum, do you plan to use also the jBPM? In that case it is still fairly easy to embed the engine, but you typically also need to setup persistence and few other things.

           

          Thanks,

          Petr

          • 2. Re: Using Drools within an Java  Enterprise Application
            jesstei

            Hello Petr,

             

            thanks for your advice.

            If I try to integrate Drools into my ear file fails to deploy and  I get several exceptions.

             

            If I add this line:

            KieServices ks = KieServices.Factory.get();

             

            I receive the following exception: java.lang.NoClassDefFoundError: org/kie/api/KieServices$Factory

            Even so I added the kie-api-6.10.Final.jar to the project and the KieService.class is available.

             

            If a add these lines:

                 @Inject

                 @KSession("ksession-rules")

                 KieSession kSession;

             

            I receive the following exception: java.lang.NoClassDefFoundError: Lorg/kie/api/runtime/KieSession; and java.lang.ClassNotFoundException: org.kie.api.runtime.KieSession.

            These .class files are also available within kie-api-6.10.Final.jar.

             

             

            Regarding your question: Do you plan to use also the jBPM? You typically also need to setup persistence and few other things.

            I need to create profiles out of the reactions initiated after the occurence of some messages. These profiles are stored within a no sql database and are taken into account for future reactions.

            I do not know if jBPM would be too much or useful in this case but persistence will be a topic anyway :-).


            Kind regards,

            jesstei

             

            • 3. Re: Using Drools within an Java  Enterprise Application
              psiroky

              Hi jesstei,

               

              unfortunately, I am not much familiar with the EARs and how the classloading works in WildFly 8. It seems the kie-api-<version>.jar is not on the classpath (for whatever reason), but I guess you already figured that out.

               

              Would it be possible to share the sources of your project (e.g. on github), so we can look at them? I believe this would be the fastest way to get it working.

               

              Thanks,

              Petr

              • 4. Re: Using Drools within an Java  Enterprise Application
                jesstei

                Hello Petr,

                 

                as soon as I have uploaded the files I will post an URL to the repro. I need to change the messages I send because they are confidential.

                 

                The repro URL is : jesstei/Drools · GitHub

                 

                Kind regards,

                jesstei

                • 5. Re: Using Drools within an Java  Enterprise Application
                  psiroky

                  Hello,

                   

                  sorry for the delay, I somehow missed the update of your post with the link to github. I will look into the sources shortly.

                   

                  One thing that struck me at first sight is that you are actually using different versions of drools artifacts, some of them are 6.0.0.Beta2 and some of them 6.2.0.Beta3. This does not necessarily cause your problem, but it is bad idea to mix the versions.

                   

                  Thanks,

                  Petr

                  • 6. Re: Using Drools within an Java  Enterprise Application
                    psiroky

                    I just briefly looked through the sources and I have following questions:

                    - is the WAR module missing? This way I can't compile the project.

                    - is the actual drools integration missing? I could not find any code that would use/call drools engine. There is a class RulesEngine, but it is empty.

                     

                    Petr

                    • 7. Re: Using Drools within an Java  Enterprise Application
                      jesstei

                      Hi Petr,

                       

                      unfortunatly, I did not receive a notification that you respond to my message.

                       

                      I wanted to integrate drools into the Class RulesEngine. But I receive the following error: ERROR [org.drools.compiler.kie.builder.impl.KieContainerImpl] (Thread-0 (HornetQ-client-global-threads-1906460542)) Unknown KieSession name: ksession-rules.

                      I am going to upload a current version to github.

                      The version mix might have occurred as I changed versions several times to try to get it working.

                       

                      Kind regards and thanks a lot for your help.

                      jesstei

                      • 8. Re: Using Drools within an Java  Enterprise Application
                        jesstei

                        Hi Petr,

                         

                        I uploaded my current .ear file to my git repro.

                         

                        Kind regards,

                        jesstei