[rules-users] Drools/Camel Integration sending messages

Edson Tirelli ed.tirelli at gmail.com
Sat Jun 11 10:51:12 EDT 2011


   Andre,

   The consequence of a rule is plain java code, so as long as you import
the proper classes and use the API correctly, it will work. Although, it
seems to me (looking only at the 2 code snippets bellow) that you could
probably simplify things if you inserted message bodies instead of the full
exchange into the session.

   My suggestion is for you to define multiple routes and use the session as
a dynamic router. Something like this: (using pseudo code)

   <route>
       <from uri="activemq:personnel.records"/>
       <policy ref="droolsPolicy">
           ...
           <to uri="drools:node1/ksession1?action=insertBody"/>
           ...
       </policy>
   </route>

   <route>
       <from uri="drools:node1/ksession1?channel=myFile"/>
       <to uri="file:target/messages/foo"/>
   </route>

   <route>
       <from uri="drools:node1/ksession1?channel=anotherChannel"/>
       <to uri=.../>
   </route>


rule "Rule 04"
dialect "mvel"
   when
       $p : Person()
   then
      channels["myFile"].send( $p );
end

rule "create new person"
dialect "mvel"
when
     ...
then
      $neu = new Person();
      $neu.firstname = "I";
      channels["anotherChannel"].send( $neu );
end


   Doing it like that, you separate the concerns more clearly. Camel is
responsible for all the middleware communication and transport, while your
Drools session will deal with the actual routing logic. It also lets your
rules to use arbitrary channel names (e.g., "myFile", "anotherChannel") that
camel routes will map into actual routes. Finally, all the internals of
camel communications (like creating messages, exchanges, etc) are handled
transparently for you.

   That is how I would do it. Hope it helps.

   Edson

2011/6/10 Andre <morpheusandre at web.de>

> here it is:
> my route:
> <code>
>    <route>
>        <from uri="activemq:personnel.records"/>
>        <policy ref="droolsPolicy">
>            <unmarshal ref="myjaxb"/>
>            <to uri="drools:node1/ksession1?action=insertExchange"/>
>            <routingSlip uriDelimiter="#">
>                <header>routingSlip</header>
>            </routingSlip>
>            <log loggingLevel="INFO" message="Message Received in Drools"/>
>            <marshal ref="myjaxb"/>
>            <to uri="file:target/messages/foo"/>
>            <log loggingLevel="INFO" message="Message received at
> fileendpoint"/>
>        </policy>
>    </route>
> </code>
> and now the rule, which works:
> <code>
> rule "Rule 04"
> dialect "mvel"
>    when
>                $exchange: Exchange()
>        eval($exchange.in.body instanceof Person )
>
>    then
>       $p = (Person)$exchange.in.body;
>       $exchange.in.setHeader("routingSlip","file:target/messages/hello");
>       System.out.println("Rule 04 Works " + $p.user);
> end
> </code>
> but i want to do something like:
> <code>
>       #$message = new JmsMessage();/doesnt work: "cannot Resolve
> Constructor"
>       $message = $exchange.copy();
>       $neu = new Person();
>       $neu.firstname = "I";
>       $message.in.body = $neu;
>       $message.in.setHeader("routingSlip","file:target/messages/bar");
> </code>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-Camel-Integration-sending-messages-tp3043844p3047520.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110611/329f4aff/attachment.html 


More information about the rules-users mailing list