Drools stateful session per request

1.2k Views Asked by At

We are trying to use Drool as our rule engine service. What we done till now is listed below

Most of our requirements satisfied by stateless session (Give a set of data, execute the rule and return the data, that's it) . But using stateless we have to compromise many of the important features provided by Drools stateful session.

So we are trying to use stateful session per request. Which means the session should get disposed as soon as the request end. Also, parallel request should not interfere each other even if the session name is same

We found about container runtime strategy configuration (Workbench > Deploy > {any container} > Process Configuration > Runtime strategy)

enter image description here

But even after configure the container strategy to Per Request, it still behave same as Singleton (the session is not getting disposed after each request)

Few place we read it as, run time strategy only implemented in jBPM

The way we make request to KIE server is shown below

 Request: POST {HOST}/kie-server/services/rest/server/containers/instances/TestRequest_1.0.4 
 {
   "lookup": "ab-session", //stateful session
   "commands": [
     {
       "insert": {
         "out-identifier": "125",
         "object": {
           "com.myteam.testrequest.Product": {
            "id": "123",
            "name": "Hoo Hoo",
            "count": 0
           }
         },
         "return-object": "true"
       }
     },
     {
       "insert": {
         "out-identifier": "126",
         "object": {
           "com.myteam.testrequest.Product": {
            "id": "123",
            "name": "Hoo Hoo",
            "count": 0
           }
         },
         "return-object": "true"
       }
     },
     {"fire-all-rules": "hf2"}
   ]
  }

We need help in achieving this requirement. Also, please help understand if we done something wrong

1

There are 1 best solutions below

0
On

In kmodule.xml you may try to add "prototype" scope, because default is "singleton":

<ksession name="SessionName" type="stateful" default="false" clockType="realtime" scope="prototype"/>