Is there a KieScanner sample application for BPM Suite and BRMS 6.1?

Solution Verified - Updated -

Environment

  • Red Hat JBoss BPM Suite (BPM Suite)
    • 6.x
  • Red Hat JBoss Business Rules Management System (BRMS)
    • 6.x

Issue

We are looking for a really simple example for KieScanner application to scan rules from a local BRMS installation. Where can I find it?

Resolution

Further general information about KieScanner can be found at Question/Problem about KieScanner against a remote BRMS/BPMS server article. The simplest code to use KieScanner can be checked below:

package com.redhat.gss.brms;

import org.drools.compiler.kproject.ReleaseIdImpl;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

public class KieScannerTest {

    final static String G = "org.kie.example";
    final static String A = "project1";
    final static String V = "1.0.0-SNAPSHOT";

    private KieSession kSession;
    private KieServices kieServices;
    private ReleaseIdImpl releaseId;
    private KieContainer kContainer;
    private KieScanner kScanner;

    @Test
    public void fireRules() throws InterruptedException {
        kieServices = KieServices.Factory.get();
        releaseId = new ReleaseIdImpl(G, A, V);
        kContainer = kieServices.newKieContainer(releaseId);
        kScanner = kieServices.newKieScanner(kContainer);
        kSession = kContainer.newKieSession();
        kScanner.start(3000);
        while (true) {
            Thread.sleep(3000);
            kSession.fireAllRules();
        }
    }
}

It will scan the provided artifact each 3 seconds. If there's an update in the artifact, it will fire the latest version of the rules. To use it in your maven project you must make sure you are using the correct artifacts. Here's a sample pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.redhat.gss.brms</groupId>
    <artifactId>kie-scanner-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>KieScanner Test</name>
    <description>KieScanner Testing for BPM Suite 6.1</description>
    <properties>
        <version.jboss.bom.brms>6.0.3.GA-redhat-1</version.jboss.bom.brms>
        <version.jboss.bom>1.0.4.Final-redhat-9</version.jboss.bom>
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.test.skip>true</maven.test.skip>
    </properties>
    <repositories>
        <repository>
            <id>bpms-xpaas</id>
            <name>BPM Suite XPaaS repository</name>
            <url>http://localhost:8080/business-central/maven2/</url>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.bom.eap</groupId>
                <artifactId>jboss-javaee-6.0-with-tools</artifactId>
                <version>6.4.0.GA</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.bom.brms</groupId>
                <artifactId>jboss-javaee-6.0-with-brms-bpmsuite</artifactId>
                <version>6.1.0.GA-redhat-2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.2-redhat-1</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
        </dependency>
        <dependency>
            <groupId>org.kie.example</groupId>
            <artifactId>project1</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>       
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Attached to this article you can find a maven project. To run it use the command mvn clean test.

Attachments

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments