Apache camel 如何使用camel从jbpm获取流程变量?

Apache camel 如何使用camel从jbpm获取流程变量?,apache-camel,jbpm,Apache Camel,Jbpm,我通过传递变量映射,通过camel在jbpm中启动一个进程。 在jbpm中,我正在更改该变量的值(这里是“name”),但我无法将该变量返回到camel。代码如下: final Map map = new HashMap(); JBPMConfiguration bPMConfiguration = new JBPMConfiguration(); bPMConfiguration.setUserName("admin"); bPM

我通过传递变量映射,通过camel在jbpm中启动一个进程。 在jbpm中,我正在更改该变量的值(这里是“name”),但我无法将该变量返回到camel。代码如下:

        final Map map = new HashMap();
        JBPMConfiguration bPMConfiguration = new JBPMConfiguration();
        bPMConfiguration.setUserName("admin");
        bPMConfiguration.setPassword("***");
         bPMConfiguration.setProcessId("HelloWorld.helloworldBusinessProcess");
        bPMConfiguration.setDeploymentId("SAN:HelloWorld:1.0");

        bPMConfiguration.setConnectionURL(new URL("http://127.0.0.1:8080/kie-wb62"));
        JBPMEndpoint bPMEndpoint = new JBPMEndpoint("jbpm:http", new JBPMComponent(), bPMConfiguration);
         JBPMProducer bPMProducer=(JBPMProducer) bPMEndpoint.createProducer();
        if (bPMProducer instanceof JBPMProducer) {
         Exchange exchange = ((JBPMProducer) bPMProducer).createExchange();
            map.put("name", "SAntanu");
            bPMConfiguration.setParameters(map);
            exchange.setPattern(ExchangePattern.OutIn);
            exchange.getOut().setHeader("CamelJBPMParameters",map);
            bPMProducer.start();
            bPMProducer.process(exchange);

           }
下面是一个示例(代码是scala的,但我相信您会明白这一点)

它使用
camel jbpm
启动流程,并使用自定义代码获取流程变量(纯kie)

在这个演示中,我使用标准的
cameljbpm
组件来启动这个过程。要获取值,需要第二个rest请求。在撰写本文时(2016年7月),camel jbpm组件尚不支持这一点。我正在使用自定义处理器发送
findVariableInstanceCommand
name
过程变量的请求。 我还列出了import语句,因为它们可能不像您想象的那么明显(注意,它们都是kie)

我正在使用jbpm workbench的招聘流程*

package demo.http
导入java.net.URL
导入org.apache.camel.Exchange
导入org.apache.camel.component.jbpm.JBPMConstants
导入org.apache.camel.scala.dsl.builder.RouteBuilder
导入org.kie.api.runtime.manager.RuntimeEngine
导入org.kie.api.runtime.process.ProcessInstance
导入org.kie.remote.client.api.RemoteRuntimeEngineFactory
导入org.kie.remote.jaxb.gen.findvariableinstanceCommand
导入org.kie.services.client.serialization.jaxb.impl.audit.JaxbVariableInstanceLog
导入scala.collection.JavaConverters_
/**
*待办事项
*/
类JBpmnRoute扩展了RouteBuilder{
“直接:jbpmRoute”==>{
//设置进程id
setHeader(JBPMConstants.PROCESS_ID,常量(“雇用”))
//在本例中:将映射从in.body复制到头[JBPMConstants.PARAMETERS]
过程((e:交换)=>{
e、 getIn().setHeader(JBPMConstants.PARAMETERS,e.in[Map[String,AnyRef]].asJava)
})
//开始这个过程
至jbpm:http://localhost:8080/jbpm-控制台?用户名=管理员&密码=管理员”
+“&deploymentId=org.jbpm:HR:1.0&operation=startProcess”)
//获取过程变量(在本例中为“名称”)
过程((e:交换)=>{
val rte:RuntimeEngine=RemoteRuntimeEngineFactory.newRestBuilder()
.addUrl(新URL(“http://localhost:8080/jbpm-控制台/“”)。添加用户名(“管理员”)。添加密码(“管理员”)
.addDeploymentId(“org.jbpm:HR:1.0”).build()
val cmd:FindVariableInstanceCommand=新的FindVariableInstanceCommand()
cmd.setProcessInstanceId(e.in[ProcessInstance].getId)
cmd.setVariableId(“名称”)
val result=rte.getKieSession.execute(cmd).asInstanceOf[java.util.List[AnyRef]].asScala
e、 in=result.head.asInstanceOf[JaxbVariableInstanceLog].getValue
})
日志(“名称${body}的值”)
}
}
使用的测试用例

@测试
def exampleTest():单位={
val参数:Map[String,AnyRef]=Map(“name”->“Mike Wheeler”)
val response=template.requestBody(“direct:jbpmRoute”,
param,classOf[String])
Assert.assertThat(响应,Is.Is(“Mike Wheeler”))
}
*)如果要快速测试,请运行以下docker容器

docker run -Pd -p 8080:8080 -p 8001:8001 --name jbpm-workbench docker.io/jboss/jbpm-workbench-showcase
下面是一个示例(代码是scala的,但我相信您会明白这一点)

它使用
camel jbpm
启动流程,并使用自定义代码获取流程变量(纯kie)

在这个演示中,我使用标准的
cameljbpm
组件来启动这个过程。要获取值,需要第二个rest请求。在撰写本文时(2016年7月),camel jbpm组件尚不支持这一点。我正在使用自定义处理器发送
findVariableInstanceCommand
name
过程变量的请求。 我还列出了import语句,因为它们可能不像您想象的那么明显(注意,它们都是kie)

我正在使用jbpm workbench的招聘流程*

package demo.http
导入java.net.URL
导入org.apache.camel.Exchange
导入org.apache.camel.component.jbpm.JBPMConstants
导入org.apache.camel.scala.dsl.builder.RouteBuilder
导入org.kie.api.runtime.manager.RuntimeEngine
导入org.kie.api.runtime.process.ProcessInstance
导入org.kie.remote.client.api.RemoteRuntimeEngineFactory
导入org.kie.remote.jaxb.gen.findvariableinstanceCommand
导入org.kie.services.client.serialization.jaxb.impl.audit.JaxbVariableInstanceLog
导入scala.collection.JavaConverters_
/**
*待办事项
*/
类JBpmnRoute扩展了RouteBuilder{
“直接:jbpmRoute”==>{
//设置进程id
setHeader(JBPMConstants.PROCESS_ID,常量(“雇用”))
//在本例中:将映射从in.body复制到头[JBPMConstants.PARAMETERS]
过程((e:交换)=>{
e、 getIn().setHeader(JBPMConstants.PARAMETERS,e.in[Map[String,AnyRef]].asJava)
})
//开始这个过程
至jbpm:http://localhost:8080/jbpm-控制台?用户名=管理员&密码=管理员”
+“&deploymentId=org.jbpm:HR:1.0&operation=startProcess”)
//获取过程变量(在本例中为“名称”)
过程((e:交换)=>{
val rte:RuntimeEngine=RemoteRuntimeEngineFactory.newRestBuilder()
.addUrl(新URL(“http://localhost:8080/jbpm-控制台/“”)。添加用户名(“管理员”)。添加密码(“管理员”)
.addDeploymentId(“org.jbpm:HR:1.0”).build()
val cmd:FindVariableInstanceCommand=新的FindVariableInstanceCommand()
cmd.setProcessInstanceId(e.in[ProcessInstance].getId)
cmd.setVariableId(“名称”)
val result=rte.getKieSession.execute(cmd).asInstanceOf[java.util.List[AnyRef]].asScala
e、 in=result.head.asInstanceOf[JaxbVariableInstanceLog].getValue
})
日志(“名称${body}的值”)
}
}
使用的测试用例

@测试
def exampleTest():单位={
val参数:映射[字符串,任意值]