JBoss Drools is a complete enterprise platform for rules-based application development, workflow, administration, and event processing. It also provides an integration with JBossESB to support content based routing. You define the content based routing algorithm in a set of rules.
But, Drools might be a larger tool than you may want to use for some routing tasks.
Two additional (and simpler) approaches for content based routing were just added to the JBossESB project. (Note that these were added to the JBoss ESB project in trunk here: http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk and should be in the next project release.) Let's take a look at these new approaches for content based routing as illustrated in the "jbos-esb.xml" file of the "fun_cbr" quickstart sample application:
XPath Content Based Routing
To configure XPath content based routing you define a service like this:
32 <service category="Fun_CBRServices_ESB" name="XPath_FunCBRService_ESB" description="ESB Listener - for the native clients" invmScope="GLOBAL">The "cbrAlias" property defined on line 39 indicates that one of the new approaches for content based routing is to be used. On line 41 the namespace is defined and lines 42-44 define the actual routes. Note that this is completely defined in the jboss-esb.xml file. No additional configuration files are needed.
33 <listeners>
34 <!-- Gateway -->
35 <jms-listener name="TheGateway" busidref="xpathQuickstartGwChannel" is-gateway="true" />
36 </listeners>
37 <actions mep="OneWay">
38 <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
39 <property name="cbrAlias" value="XPath"/>
40 <property name="destinations">
41 <namespace prefix="ord" uri="http://org.jboss.soa.esb/Order" />
42 <route-to service-category="BlueTeam" service-name="GoBlue" expression="/ord:Order[@statusCode='0']" />
43 <route-to service-category="RedTeam" service-name="GoRed" expression="/ord:Order[@statusCode='1']" />
44 <route-to service-category="GreenTeam" service-name="GoGreen" expression="/ord:Order[@statusCode='2']" />
45 </property>
46 </action>
47 </actions>
48 </service>
Regex Content Based Routing
52 <service category="Fun_CBRServices_ESB" name="Regex_FunCBRService_ESB" description="ESB Listener - for the native clients" invmScope="GLOBAL">Again, Line 59 defines the cbrAlias property and lines 63-65 define the actual paths. On line 60, we have a reference to the external file that contains the XPath expressions that will govern the routing. That file looks like this:
53 <listeners>
54 <!-- Gateway -->
55 <jms-listener name="TheGateway" busidref="regexQuickstartGwChannel" is-gateway="true" />
56 </listeners>
57 <actions mep="OneWay">
58 <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
59 <property name="cbrAlias" value="Regex"/>
60 <property name="ruleSet" value="/regex-rules.properties"/>
61 <property name="ruleReload" value="true"/>
62 <property name="destinations">
63 <route-to destination-name="blue" service-category="BlueTeam" service-name="GoBlue" />
64 <route-to destination-name="red" service-category="RedTeam" service-name="GoRed" />
65 <route-to destination-name="green" service-category="GreenTeam" service-name="GoGreen" />
66 </property>
67 </action>
68 </actions>
69 </service>
1 blue=.* statusCode="0".*It's important to note that any applications built with Drools-based content based routing will continue to function without needing any changes or migrations.
2 red=.* statusCode="1".*
3 green=.* statusCode="2".*
To sum it up, content based routing has always been a flexible way to route messages to services. With these changes to JBossESB, it's even easier to use.
References
[1] http://jboss-soa-p.blogspot.com/2009/07/when-content-knows-way-content-based.html
6 comments:
Nice one Len!!
This is great Len! My team has written various CBR actions that use XPath but we're always happy to not use custom code.
Nice article Len! But I have some note for Regex Content Based Routing section (correct me if I'm wrong, please) I believe that the expressions in the regex-rules.properties file (on line 60) are not XPath but RegEx ones :)
Nice is great article Len!
Nike Air Force One
Nike Air Force One shoes
Cheap Nike Air Force One shoes
Men's Air Max 90
Women's-Air Max 90
Air Max 93
Hello.
I think it worth mentioning that destination service group/name combination should be unique in one CBR action - you can't create few rules which lead to one service. They use this combination as a key in a Map so some destinations will not work. Took me few hours debugging for JBoss 5.0.2
Post a Comment