ServiceMix Drools
The ServiceMix Drools component provides JBI integration to the Drools Rules Engine.
Note that this component is only available in releases >= 3.1 and deprecate the older lightweight Drools component
JbiHelper
DRL files deployed to the servicemix-drools
engine have access to a JbiHelper
class in a global variable named jbi
which provides the following attributes and methods:
Attribute |
Description |
---|---|
jbi.getEndpoint() |
The |
jbi.getContent() |
A |
jbi.getChannel() |
A |
jbi.getClient() |
A |
jbi.getExchange() |
The |
jbi.getLogger() |
A |
Methods |
Description |
---|---|
jbi.route(uri) |
Route the current exchange to the given uri |
jbi.fault(content) |
Returns a fault using the given string as the xml fault |
jbi.answer(content) |
Sends an Out message using the given string as the xml content |
The received exchange is added as a fact to the working memory.
Note that, due to Drools limited support for non simple java beans accessors, the JBI MessageExchange and NormalizedMessage are wrapped with simple beans.
Router
<drools:endpoint service="test:service" endpoint="endpoint" ruleBaseResource="classpath:router.drl" />
package org.apache.servicemix.drools import org.apache.servicemix.drools.model.Exchange; global org.apache.servicemix.drools.model.JbiHelper jbi; rule "Unspecified id" when me : Exchange( status == Exchange.ACTIVE, in : in != null ) eval( in.xpath("/test/@id <= 0") ) then jbi.fault( "<fault>Id must be > 0</fault>" ); end rule "Route to target1" when me : Exchange( status == Exchange.ACTIVE, in : in != null ) eval( in.xpath("/test/@id = 1") ) then jbi.route( "service::target1" ); end rule "Route to target2" when me : Exchange( status == Exchange.ACTIVE, in : in != null ) eval( in.xpath("/test/@id = 2") ) then jbi.route( "service::target2" ); end rule "Route to target3" when me : Exchange( status == Exchange.ACTIVE, in : in != null ) eval( in.getProperty("prop") != null ) then jbi.route( "service::target3" ); end