Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Service Mix Drools

Adding A Service mix drools  

mvn archetype:create  -DarchetypeGroupId=org.apache.servicemix.tooling  -DarchetypeArtifactId=servicemix-drools-service-unit  -DarchetypeVersion=2010.01  -DgroupId=com.bytes.tutorial  -DartifactId=drools-su -Dversion=1.01

groupId, Value: com.bytes.tutorial
packageName, Value: com.bytes.tutorial
package, Value: com.bytes.tutorial
version, Value: 1.01
artifactId, Value: com.bytes.drools




here is the example 

i have xml files in a folder C:\SOURCE and the content of them is some thing like this below, based on the content

the drools will be configured in such a way that their destination is decided by the drools.
File1
<?xml version="1.0" encoding="UTF-8"?>
<test id="1">
this file matches rule 1
</test>

File2
<?xml version="1.0" encoding="UTF-8"?>
<test id="2">
this file matches rule 2
</test>

File3
<?xml version="1.0" encoding="UTF-8"?>
<test id="3">
this file matches rule 3
</test>

Then the D-rools are configured like this.
the above rules check the id attribute present in the xml based on that 
they send the messages to one of file_sender1,file_sender2,file_sender3.
package org.apache.servicemix.drools

import org.apache.servicemix.drools.model.Exchange;

global org.apache.servicemix.drools.model.JbiHelper jbi;

rule "Route to target1"
when
me : Exchange( status == Exchange.ACTIVE, $in : in != null )
eval( $in.xpath("/test/@id = 1") )
then
jbi.route( "service:http://servicemix.apache.org/bytes/file_sender1" );
end

rule "Route to target2"
when
me : Exchange( status == Exchange.ACTIVE, $in : in != null )
eval( $in.xpath("/test/@id = 2") )
then
jbi.route( "service:http://servicemix.apache.org/bytes/file_sender2" );
end

rule "Route to target3"
when
me : Exchange( status == Exchange.ACTIVE, $in : in != null )
eval( $in.xpath("/test/@id = 3") )
then
jbi.route( "service:http://servicemix.apache.org/bytes/file_sender3" );
end


File Poller 
<file:poller service="bytes:file_poller" endpoint="file-poller"
targetService="bytes:serviceNameDR"
targetEndpoint="drools" 
file="file:C:/SOURCE">

File Sender
<file:sender service="bytes:file_sender1"
endpoint="file-sender"
directory="file:C:/DESTINATION1" />
<file:sender service="bytes:file_sender2"
endpoint="file-sender"
directory="file:C:/DESTINATION2" />
<file:sender service="bytes:file_sender3"
endpoint="file-sender"
directory="file:C:/DESTINATION3" />

the sample code can be found here download



No comments:

Post a Comment

Search 24 Bytes