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

适配Camel 3的kie-camel jar获取及KIE7.73与Camel3集成文档咨询

适配Camel 3的kie-camel及Karaf集成方案

关于适配Camel 3的kie-camel jar

官方并未提供直接适配Camel 3的kie-camel模块——从KIE 7.x系列的维护情况来看,kie-camel模块长期停留在基于Camel 2.x的实现,后续版本也没有针对Camel 3做升级适配。如果必须结合Camel 3与KIE/Drools使用,有两种可行方案:

  • 自行改造kie-camel源码:下载对应版本的kie-camel源码,修改其中依赖的Camel API(比如KiePolicy类中与Camel 3 Policy接口不兼容的方法),重新编译打包。重点关注Camel 3中Policy接口的方法签名变化,比如wrapRouteContext等方法的参数或返回值调整。
  • 放弃kie-camel,直接用Camel原生API集成Drools:绕过kie-camel的封装,直接在Camel路由里调用Drools的KIE容器(KieContainer)和会话(KieSession)。示例代码大致如下:
from("direct:droolsRoute")
    .process(exchange -> {
        // 通过Karaf的OSGi服务获取KieContainer
        KieContainer kieContainer = ...; 
        KieSession kieSession = kieContainer.newKieSession();
        try {
            Object payload = exchange.getIn().getBody();
            kieSession.insert(payload);
            kieSession.fireAllRules();
            exchange.getIn().setBody(payload);
        } finally {
            kieSession.dispose();
        }
    });

Karaf 4.4.0中集成KIE 7.73.0.Final、Drools 7.73.0.Final与Camel 3.11.7

依赖配置(Karaf特性/Blueprint)

  1. 先安装必要的Karaf特性:
feature:install camel-core camel-blueprint drools-kie-ci drools-osgi
  1. 在Blueprint配置中声明KIE容器:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <bean id="kieContainer" class="org.kie.api.runtime.KieContainer" factory-method="newKieContainer">
        <argument type="org.kie.api.KieServices" factory-method="get"/>
        <argument value="your-kie-group:your-kie-artifact:your-version"/>
    </bean>

    <!-- Camel路由配置 -->
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route id="droolsIntegrationRoute">
            <from uri="direct:processOrder"/>
            <process ref="droolsProcessor"/>
            <to uri="log:processedOrder"/>
        </route>
    </camelContext>

    <bean id="droolsProcessor" class="com.yourcompany.DroolsProcessor">
        <property name="kieContainer" ref="kieContainer"/>
    </bean>
</blueprint>
  1. 处理器类示例:
public class DroolsProcessor implements Processor {
    private KieContainer kieContainer;

    @Override
    public void process(Exchange exchange) throws Exception {
        KieSession kieSession = kieContainer.newKieSession();
        try {
            Order order = exchange.getIn().getBody(Order.class);
            kieSession.insert(order);
            kieSession.fireAllRules();
            exchange.getIn().setBody(order);
        } finally {
            kieSession.dispose();
        }
    }

    // kieContainer的setter方法
    public void setKieContainer(KieContainer kieContainer) {
        this.kieContainer = kieContainer;
    }
}

注意事项

  • 确保KIE/Drools的OSGi包与Karaf 4.4.0兼容:KIE 7.73.0.Final的OSGi模块已适配较新的OSGi规范,与基于OSGi R7的Karaf 4.4.0兼容,但要注意避免依赖冲突,尤其是日志框架(建议使用Karaf默认的SLF4J)。
  • Camel 3与Karaf的适配:安装Camel 3.11.7对应的Karaf特性时,要选择与Karaf 4.4.0匹配的版本,避免版本不兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 21:18:16