We support Rules based routing using the Drools rule engine. The basic idea is you expose a DroolsComponent at some service/interface/operation endpoint in ServiceMix then let it perform rules based routing, or other actions as required.

You can deploy a DroolsComponent with a rule base which will be fired when it is invoked. The rule base is then in complete control over messge dispatching.

{snippet:id=drools|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/example.xml}

Then you can create your Drools rule base using whatever Drools mechanism you wish. For example here's the default Java semantic module to perform custom routing

{snippet:id=drools|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/rulebase.xml}

Using the JBI language

Drools allows you to provide different DSLs (domain specific languages) so we have added a DSL for JBI. Here is an example of it in use

{snippet:id=drools|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules.xml}

As you can see the <jbi:invoke> element will invoke a service endpoint; you can specify a service name, interface name and/or an operation name on this tag - they are all QNames using the namespace mapping of the XML document.

In addition the condition is an XPath expression. Again the XML namespaces in this document are available to the XPath expression.

  • No labels