|
Page Edited :
SM :
servicemix-drools
servicemix-drools has been edited by Lars Heinemann (Aug 14, 2008). Content:ServiceMix DroolsThe ServiceMix Drools component provides JBI integration to the Drools Rules Engine. This Service Engine can be used to deploy a rules set that will implement a router or an actual service. A router will mostly act as a transparent proxy between the consumer and the target service provider mad will mostly be implemented by the jbi.route(uri) method below. This method creates a new exchange identical to the one received by the component and will send it to the specified destination. You can also send back a Fault if needed. A router can also be implemented by using directly the JBI Apis (available with the jbi helper) by using the provided client. This component can also be used to implement a real service, as shown in the Fibonnacci example Note that this component is only available in releases >= 3.1 and deprecate the older lightweight Drools component JbiHelperDRL 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:
The received exchange is added as a fact to the working memory. Injecting additional beans in the rulesThe JbiHelper is injected by the component itself so that you can access the current exchange and handle it. However, there are cases where you need to add your own beans and inject them in the rules definition. Starting from ServiceMix 3.2, this is now possible using the following syntax: <drools:endpoint service="test:service" endpoint="endpoint" ruleBaseResource="classpath:router.drl" globals="#globals" /> <util:map id="globals"> <entry key="helper" value-ref="helper" /> </util:map> <bean id="helper" class="org.example.Helper" />
Then you can use it from your rules ... RouterEndpoint definition <drools:endpoint service="test:service" endpoint="endpoint" ruleBaseResource="classpath:router.drl" /> Rules definitions 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 |
Unsubscribe or edit your notifications preferences
