JBoss.org Community Documentation

- Prev
- Next

## Chapter 2. Spring Integration

## 2.1. Integration with Drools Expert

In this section we will explain the drools namespace.

### 2.1.1. Define a Resource

Execution nodes are a context to regsiter ksessions and kbases against for lookup.

#### 2.1.1.1. <drools:execution-node>'s parameters as attributes:

Table 2.1.

Attribute | Description | Required
--- | --- | ---
id | Bean's id is the name to be reference from other beans. | Yes

#### 2.1.1.2. <drools:resource>'s parameters as attributes:

Table 2.2.

Attribute | Description | Required
--- | --- | ---
id | Bean's id is the name to be reference from other beans. | Yes, but can be omitted when this tag is nested.
source | The path to the file containing the actual resource. | Yes
type | Type of the Resource as is defined in class `ResourceType`. | No, default to DRL

#### 2.1.1.3. <drools:resource>'s parameters as nested elements:

When configuring a decision table resource you can nest a <drools:decisiontable-conf> tag to configure the resource.

Table 2.3.

Attribute | Description | Required
--- | --- | ---
input-type | Decision Table input type: XLS or CSV | No
worksheet-name | The worksheet name to be used in the when using an XLS | No

Example 2.1. resource definition example

    <drools:resource source="classpath:org/drools/IntegrationExampleTest.xls"

                     type="DTABLE">

       <drools:decisiontable-conf input-type="XLS" worksheet-name="Tables_2" />

    </drools:resource>

#### 2.1.1.4. Define a KnowledgeBase

##### 2.1.1.4.1. <drools:kbase>'s parameters as attributes:

Table 2.4.

Attribute | Description | Required
--- | --- | ---
id | Bean's id is the name to be referenced from other beans. | Yes
node | Execution-Node context to register the kbase with | no

##### 2.1.1.4.2. <drools:kbase>'s parameters as nested elements:

A Knowledge Base has a 0..n resources. Has two nested elements, resources and configuratoins. Thoe resources can be inner elements or references, using the "ref" attribute.

Example 2.2. kbase definition example

    <drools:kbase id="kbase1" node="node1">

       <drools:resources>

          <drools:resource source="classpath:org/drools/spring/IntegrationExampleTest.xls"

                        type="DTABLE">

             <drools:decisiontable-conf input-type="XLS" worksheet-name="Table_2" />

          </drools:resource>

          <drools:resource ref="resource1"/>

          <drools:resource source="classpath:org/drools/container/spring/model.xsd" />

       </drools:resources>

       <drools:configuration>

           <drools:mbeans enabled="true" />

          <drools:accumulate-functions>

             <drools:accumulate-function name="func1" ref="func1Instance" />

             <drools:accumulate-function name="func1" ref="func2Instance" />

          </drools:accumulate-functions>

       </drools:configuration>

    </drools:kbase>

- advanced-process-rule-integration

  - enabled = true : false

- multithread

  - enabled = true : false

  - max-threads = 1..n

- mbeans

  - enabled = true : false

- event-processing-mode

  - mode = STREAM : CLOUD

- accumulate-functions

  - accumulate-function 0..n

    - name = String

    - ref = String

- evaluators

  - evaluator 0..n

    - name = String

    - ref = String

- assert-behavior

  - mode = IDENTITY : EQUALITY

Figure 2.1. Knowledge Base Configuration Options

#### 2.1.1.5. Define KnowledgeSessions

##### 2.1.1.5.1. <drools:ksession>'s parameters as attributes:

Table 2.5.

Attribute | Description | Required
--- | --- | ---
id | Bean's id is the name to be referenced from other beans. | Yes
type | is the session stateful or stateless? | Yes
name |  | No; defaults to id when omitted.
node | Execution-Node context to register the ksession with | no

Example 2.3. ksession definition example

    <drools:ksession id="ksession1" type="stateless"

                      name="stateless1" kbase="kbase1"/>

    <drools:ksession id="ksession2" type="stateful" kbase="kbase1"/>

    <drools:ksession id="ksession3" type="stateful" kbase="kbase2>

       <drools:batch>

          <drools:insert-object ref="person" />

          <drools:set-global identifier="list1">

              <bean class="java.util.ArrayList" />

          </drools:set-global>

          <drools:startProcess process-id="start fire">

       </drools:batch>

       <drools:configurations>

         <drools:keep-reference enabled="false" />

         <drools:clock-type type="PSEUDO"  />

       </drools:configurations>

    </drools:ksession>

- keep-reference

  - enabled = true : false

- clock-type

  - type = REALTIME : PSEUDO

- jpa-persistence

  - transaction-manager

    - ref = String

  - entity-manager-factory

    - ref = String

  - variable-persisters

    - for-class = String

    - implementation = String

Figure 2.2. Knowledge Session Configuration Options

- insert-object

  - ref = String (optional)

  - Anonymous bean

- set-global

  - identifier = String (required)

  - reg = String (optiona)

  - Anonymous bean

- fire-all-rules

  - max : n

- fire-until-halt

- start-process

  - parameter

    - identifier = String (required)

    - ref = String (optional)

    - Anonymous bean

- signal-event

  - ref = String (optional)

  - event-type = String (required)

  - process-instance-id =n (optional)

Figure 2.3. Initialization Batch Commands

Example 2.4. ksession JPA configuraiton example

    <drools:kstore id="kstore" /> <!-- provides KnowledgeStoreService implementation -->

    <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

       <property name="dataSource" ref="ds" />

       <property name="persistenceUnitName" value="org.drools.persistence.jpa.local" />

    </bean>

    <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">

       <property name="entityManagerFactory" ref="myEmf" />

    </bean>

    <drools:ksession id="jpaSingleSessionCommandService" type="stateful"  kbase="kbProcessWorkItems">

       <drools:configuration>

          <drools:jpa-persistence>

             <drools:transaction-manager ref="txManager" />

             <drools:entity-manager-factory ref="myEmf" />

          </drools:jpa-persistence>

       </drools:configuration>

    </drools:ksession>

- PrevChapter 1. Apache Camel Integration
- Top of page
- Front page
- NextChapter 3. Drools Server