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.

<sm:activationSpec componentName="droolsRouter" 
					 service="foo:droolsRouter">
	<sm:component><bean class="org.apache.servicemix.components.drools.DroolsComponent">
  	<property name="ruleBaseResource" value="classpath:org/apache/servicemix/components/drools/rulebase.xml" />
  </bean></sm:component>
</sm:activationSpec>

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

<rule-set name="cheese rules"
  xmlns="http://drools.org/rules"
  xmlns:java="http://drools.org/semantics/java">

  <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
  <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
  <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>

  <rule name="Ignore 2 message">

    <parameter identifier="exchange">
      <class>javax.jbi.messaging.MessageExchange</class>
    </parameter>
    <java:condition>"2".equals(exchange.getMessage("in").getProperty("idText")) == false</java:condition>
    <java:consequence>
        // lets try send a message
        jbi.forwardToService("http://servicemix.org/cheese/", "receiver");
    </java:consequence>
  </rule>

</rule-set>

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

<rule-set name="cheese rules"
  xmlns="http://drools.org/rules"
  xmlns:jbi="http://drools.org/semantics/servicemix"
  xmlns:foo="http://servicemix.org/cheese/">

  <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
  <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
  <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>

  <rule name="Ignore 2 message">
    <parameter identifier="exchange">
      <class>javax.jbi.messaging.MessageExchange</class>
    </parameter>

    <jbi:condition>/*/@id != 2</jbi:condition>
    <jbi:invoke service="foo:receiver"/>
  </rule>

</rule-set>

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.