You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Workbench更新规则后Kie Server容器未同步更新问题求助

Drools Kie Server 更新规则后仍返回旧结果的解决办法

我之前碰到过一模一样的问题,折腾了好一阵才找到根源,你这种情况大概率是Kie Server没正确加载更新后的规则容器,给你几个实用的排查和解决方向:

  • 检查容器ID是否绑定了旧版本
    你代码里硬编码了容器ID WorkshopBRMS_1.0.1,如果更新规则后你发布了新的版本(比如1.0.2),但代码还是调用旧版本的容器,肯定会得到旧结果。建议要么改成使用不带版本号的容器名(比如WorkshopBRMS),让Kie Server自动路由到最新部署的版本;要么把容器ID放到配置文件里,更新规则后同步修改配置。

  • 手动触发容器刷新/重启
    有时候Kie Server不会主动感知Workbench的部署更新,你可以通过REST接口手动刷新容器:

    # 刷新容器的版本
    POST http://你的KieServer地址/kie-server/services/rest/server/containers/WorkshopBRMS_1.0.1/release-id
    Headers: Content-Type: application/json
    Body: {"release-id":{"groupId":"你的项目groupId","artifactId":"WorkshopBRMS","version":"1.0.1"}}
    

    或者直接重启容器:

    POST http://你的KieServer地址/kie-server/services/rest/server/containers/WorkshopBRMS_1.0.1/restart
    
  • 核对Kie Server与Workbench的同步配置
    打开Kie Server容器里的kie-server.properties文件,确保以下配置正确:

    kie.server.controller=http://你的Workbench地址/kie-wb/rest/controller
    kie.server.controller.user=你的管理员账号
    kie.server.controller.pwd=你的管理员密码
    kie.server.sync.deployments=true
    

    尤其是kie.server.sync.deployments=true这个参数,它控制Kie Server是否自动从Workbench同步最新的部署信息,如果设成false,更新就不会自动生效。

  • 清理Kie Server的本地缓存
    Docker容器里可能残留了旧的规则包缓存,你可以进入Kie Server容器,删除/opt/jboss/wildfly/standalone/data/kie目录下的所有文件,然后重启容器,这样就能确保加载最新的规则包了。

附上你提供的执行代码:

public void executeCommands() { 
    ErrorWK err=new ErrorWK(); 
    err.setErrorApp("NotifyEmployee"); 
    err.setErrorCode("111"); 
    err.setErrorDesc("Error in the service"); 
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration( URL,USER,PASSWORD); 
    Set<Class<?>> allClasses = new HashSet<Class<?>>(); 
    allClasses.add(ErrorWK.class); 
    config.addExtraClasses(allClasses); 
    KieServicesClient rulesClient = KieServicesFactory.newKieServicesClient(config); 
    System.out.println("== Sending commands to the server =="); 
    KieCommands commandsFactory = KieServices.Factory.get().getCommands(); 
    Command<?> insert = commandsFactory.newInsert(err, "InObject", false, ""); 
    Command<?> fireAllRules = commandsFactory.newFireAllRules("Fired"); 
    Command<?> getObjects = commandsFactory.newGetObjects("OutObject"); 
    Command<?> dispose=commandsFactory.newDispose(); 
    Command<?> batchCommand = commandsFactory.newBatchExecution(Arrays.asList(insert, fireAllRules,getObjects, dispose)); 
    ServiceResponse<String> executeResponse = rulesClient.executeCommands("WorkshopBRMS_1.0.1", batchCommand); 
    Marshaller marshaller = MarshallerFactory.getMarshaller(config.getExtraClasses(), MarshallingFormat.JAXB, this.getClass().getClassLoader()); 
    ExecutionResultImpl results = marshaller.unmarshall(executeResponse.getResult(), ExecutionResultImpl.class); 
    ArrayList<Object> objects = (ArrayList<Object>) results.getResults().get("OutObject"); 
    System.out.println("Rules fired: " + results.getValue("Fired")); 
    //System.out.println(objects); 
    for(java.util.Iterator<Object> it=objects.iterator();it.hasNext();) { 
        Object obj=(Object) it.next(); 
        if(obj instanceof ErrorWK){ 
            ErrorWK test= (ErrorWK)obj; 
            System.out.println("Error: " + test.getErrorApp() + "/" + test.getErrorCode() + "/" + test.getErrorDesc()); 
            System.out.println("_________________________________________________________________________________"); 
        }else { 
            System.out.println("Object does not belong to any of the defined classes:" + obj.toString()); 
        } 
    } 
}

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:32:54