Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The ServiceMix Drools component provides JBI integration to the Drools Rules Engine.

This Service Engine It can be used to deploy a rules set that will implement a router or an actual service.

...

This component can also be used to implement a real service, as shown in the Fibonnacci example. The service can act as a consumer and create / send exchanges by using the client provided by the jbi helper.

Maven Archetype

You can create a Drools Service Unit using the servicemix-drools-service-unit Maven archetype:

Code Block

mvn archetype:create \
  -DarchetypeGroupId=org.apache.servicemix.tooling \
  -DarchetypeArtifactId=servicemix-drools-service-unit \
  -DarchetypeVersion=2010.01 \
  -DgroupId=your.group.id \
  -DartifactId=your.artifact.

...

id \
  -Dversion=your-version

Once you've customized the service unit, simply install the SU:

Code Block

mvn install
Info

Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
To add your SU in a SA, you need to define it in the dependency sets:

Code Block

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>your.artifact.id</artifactId>
  <version>your-version</version>
</dependency>

Endpoint Configuration

Code Block
langxml

<beans xmlns:drools="http://servicemix.apache.org/drools/1.0"
       xmlns:replaceMe="http://servicemix.apache.org/replaceMe">

  <drools:endpoint service="replaceMe:serviceName" endpoint="drools"
    ruleBaseResource="classpath:router.drl"
    namespaceContext="#nsContext"/>

  <drools:namespace-context id="nsContext">
    <drools:namespaces>
      <drools:namespace prefix="bar">http://servicemix.apache.org/bar</drools:namespace>
    </drools:namespaces>
  </drools:namespace-context>

</beans>
Info
titleEndpoint Attributes
borderStylesolidbgColor='lightblue'

Name

Type

Description

Required

endpoint

String

JBI Endpoint Name

no (will be auto-generated if not specified

service

QName

JBI Server Name

no (will be auto-generated if not specified)

ruleBaseResource

URL

DRL File

The path to the DRL file

yes

namespaceContext

namespace-context bean

Drool Namespace Context

no

JBI Helper

Note that this component is only available in releases >= 3.1 and deprecate the older lightweight Drools component

...

DRL 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.
Note that, due to Drools limited support for non simple java beans accessors, the JBI MessageExchange and NormalizedMessage are wrapped with simple beans.

Injecting additional beans in the rules

The 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:

Code Block
langxml

<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" />

In the rules definition, just add:

Code Block

global org.example.Helper helper;
Tip
Extend your xbean.xml namespace
Extend your xbean.xml namespace

Don't forget to add the namespace for the util element.

Code Block

xmlns:util="http://www.springframework.org/schema/util"

Then you can use it from your rules ...

Router

Code Block
langxml
titleEndpoint definition
<drools:endpoint  service="test:service"
                  endpoint="endpoint"
                  ruleBaseResource="classpath:router.drl" />

...