0
我是Kie Workbench和Execution Server的新手。我正在使用Java Rest调用来在kie工作台中运行规则。请找到以下代码:Drools - 检索输出对象
private String kieServerUrl;
private String kieServerContainerId;
private String KieServerUsername;
private String kieServerPassword;
private RuleServicesClient ruleClient;
private static final String INPUT_OUT_IDENTIFIER = "Input";
private static final String SESSION_OBJECTS = "SessionObjects";
private static final String RUN_ALL_RULES = "RunAllRules";
public void init() {
final KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(kieServerUrl, KieServerUsername, kieServerPassword);
config.setMarshallingFormat(MarshallingFormat.XSTREAM);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(config);
ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
}
@Override
public Output process(final Input input) {
Output output = null;
logger.debug("Running rules ..");
BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl();
executionCommand.getCommands().add(new InsertObjectCommand(input, INPUT_OUT_IDENTIFIER));
executionCommand.getCommands().add(new FireAllRulesCommand(RUN_ALL_RULES));
executionCommand.getCommands().add(new GetObjectsCommand(null, SESSION_OBJECTS));
logger.debug("Sending commands to the server");
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(kieServerContainerId, executionCommand);
if(response.getType().equals(ServiceResponse.ResponseType.SUCCESS)){
logger.debug("Commands executed with success! Response: ");
final ExecutionResultImpl result = (ExecutionResultImpl) response.getResult();
ArrayList<Object> values = (ArrayList<Object>)result.getValue(SESSION_OBJECTS);
}else{
logger.error("Error executing rules. Message: {}", response.getMsg());
}
logger.debug("...finished running rules.");
return output;
}
规则在规则期间被正确执行并且输出对象被立即执行。一个问题是当我再次调用这个方法来第二次执行规则时,我收到两个Output对象,并且对于每个后续调用,我都会得到一个额外的对象。看来会话中的对象被存储并且不会被每个调用清除。我怎样才能达到这一点,每一个电话我只会得到一个输出对象?
如何验证KIE执行服务器会话配置是无状态的? –
我更新了如何验证。完成后请接受答案。 – Jeff