如何在Kie中将决策服务作为无状态会话进行调用(RedHat Decision Manager) [英] How to invoke decision service as a stateless session in Kie (RedHat Decision Manager)

查看:70
本文介绍了如何在Kie中将决策服务作为无状态会话进行调用(RedHat Decision Manager)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了RedHat Decision Manager 7.3,可以部署决策服务.到目前为止,我一直在使用/server/containers/instances/{containerId} 端点来调用我的服务,其中有效负载列出了将对象插入到工作内存中的命令.

但是,这是一个有状态会话,我正在尝试弄清您如何使用无状态会话来调用决策服务.关于如何通过REST API进行操作的文档尚不清楚,但是如果您使用的是Java API,则有很多示例(除非我错过了一些内容).

有人有没有通过REST进行操作的示例?

非常感谢您的帮助.

更新首先,我的意思是7.3版而不是7.4版,但是文档看起来一样.

所以看起来好像我还没有走一百万英里,从提供的文档看来,我需要在 lookup 参数中指定一个会话ID,所以我的请求将是这样的:

  {"lookup":"mysession",命令":[{插": {目的": {"com.indecision.baggage.Result":{}},返回对象":true,"out-identifier":结果"}},{插": {目的": {"com.indecision.baggage.Booking":{"fareClass":第一","baggageItems":[{"com.indecision.baggage.BaggageItem":{宽度":100,身高":100,深度":100,重量":20}}]}},返回对象":true,"out-identifier":预订"}},{插": {目的": {"com.indecision.baggage.FlightInformation":{"currentWeight":100000,"flightNumber":"IA001","maxOperatingWeight":200000}},返回对象":true,"out-identifier":"flightInfo"}},{全面规定":{"out-identifier":"firedActivations"}}]} 

但是,当我发送请求时,会收到以下错误消息:

  {"type":"FAILURE","msg":调用容器Indecision-Airlines-Baggage-Fee-Calculator时出错:在容器'Indecision-Airlines-Baggage-Fee-Calculator_1.0.0-SNAPSHOT'上找不到会话'mysession'.",结果":null} 

现在,在RH Business Central的服务器配置下,您可以为决策服务指定会话ID,但是无论我尝试执行什么操作,保存按钮始终显示为灰色.所以我的第一个问题是关于为什么或如何启用此配置的设置的任何想法?

我的第二个问题是,如果必须预先定义会话ID,那么这些服务真的不能在多个请求中真正实现无状态吗?如我所见,他们将需要预先指定要在其下执行的会话ID,而不是由KIE引擎为其创建新会话的新请求.还是我弄错了?

再次感谢您的回答.

解决方案

您可以参考本文档中的RHDM v7.4 API,以通过Java API或REST API与知识会话进行交互:

请注意,在Business Central上,会话的kmodule定义是默认无状态,这是预期的.

第二季度并非如此,正如Drools/DM手册中所述,无状态会话引用不是持久性/有状态的,因此将发生的是您的请求将以无状态方式进行处理(因为这确实是一个无状态的会话).

换句话说,对于发送到名为"mysession"的无状态会话的任何请求,无状态会话 instance 将透明地处理您的请求.

您不必为每个请求配置一个会话名称.

I have just installed RedHat Decision Manager 7.3 and can deploy a decision service. So far, I have been using the /server/containers/instances/{containerId} endpoint to call my service, where the payload lists commands to insert objects into working memory.

However, this is a stateful session, and I am trying to work out how you call a decision service using stateless sessions. The documentation is not at all clear on how to do this via the REST API, but has plenty of examples if you were using the Java API (unless I have missed something).

Does anyone have any examples on how to do this via REST?

Any help is gratefully received.

UPDATE First I meant version 7.3 not 7.4, but the documentation looks the same.

So it looks like I was not a million miles away, it looks like from the documentation supplied that I need to specify a session Id in a lookup param, so my request will be something like this:

{
  "lookup": "mysession",
  "commands": [
    {
      "insert": {
        "object": {
          "com.indecision.baggage.Result": {}
        },
        "return-object": true,
        "out-identifier": "results"
      }
    },
    {
      "insert": {
        "object": {
          "com.indecision.baggage.Booking": {
            "fareClass": "First",
            "baggageItems": [
              {
                "com.indecision.baggage.BaggageItem": {
                  "width": 100,
                  "height": 100,
                  "depth": 100,
                  "weight": 20
                }
              }
            ]
          }
        },
        "return-object": true,
        "out-identifier": "booking"
      }
    },
    {
      "insert": {
        "object": {
          "com.indecision.baggage.FlightInformation": {
            "currentWeight": 100000,
            "flightNumber": "IA001",
            "maxOperatingWeight": 200000
          }
        },
        "return-object": true,
        "out-identifier": "flightInfo"
      }
    },
    {
      "fire-all-rules": {
        "out-identifier": "firedActivations"
      }
    }
  ]
}

However when I send in the request, I get the following error message:

{
  "type": "FAILURE",
  "msg": "Error calling container Indecision-Airlines-Baggage-Fee-Calculator: Session 'mysession' not found on container 'Indecision-Airlines-Baggage-Fee-Calculator_1.0.0-SNAPSHOT'.",
  "result": null
}

Now in RH Business Central under the server configurations you can specify a session Id for the decision service, but the Save button is always greyed out regardless of what I try. So my first question is any ideas as to why or how enable the setting of this config?

My second question is if session Id's have to be defined up front then really these services cannot be truly stateless across multiple requests? As I see it, they would need to up front specify what session Id they want to execute under, rather than new requests having a new session created for them by the KIE engine. Or have I got that wrong?

Again thanks in advance for any answers.

解决方案

You can reference this document for RHDM v7.4 API to interact with a knowledge session via either the Java API or REST API: doc link

I believe is a pertinent document so it will show you side-by-side the Java API and its REST API equivalent, so you can use it for your use-case.

The example reported there is relevant to stateless session as well, as long as you use the Batch command to wrap all of your commands; in other words, to me the examples reported in that document are expected to work with stateless session, no problem. If you experience otherwise don't hesitate to report it as a bug

Following the update on the original question

Q1: no, the attached screenshot in the question is about "process configuration". If you want to name a session purposefully, with your Project open in Business Central in the horizontal tab "Settings" in the vertical tab "Kie bases" you can edit the equivalent of the kmodule.xml and name your knowledge bases and session as desired. This identifier will then be the one to reference with the batch command.

Quick example screenshot for your reference:

Please notice on Business Central kmodule definition of session are by default stateless, which is expected.

Q2 not really, as described in the Drools/DM manual, a stateless session reference is not persisted/stateful, so what will happen is that your request will be handled in a stateless manner (because it's indeed a stateless session).

In other words, for any request sent to that stateless session named "mysession", a stateless session instance will handle your request, transparently.

You do not have to configure one session name per request.

这篇关于如何在Kie中将决策服务作为无状态会话进行调用(RedHat Decision Manager)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆