osgi5——camel整合activiti

activiti是工作流,它可以实现一些请假或者面试等业务上的工作流,也可以实现ESB上一些服务编排,以便适应千变万化的互联网。

下面了解下他怎么和camel实现服务编排

blueprint.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf"
           xmlns:cxfcore="http://cxf.apache.org/blueprint/core"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
http://aries.apache.org/xmlns/jpa/v1.1.0 http://aries.apache.org/schemas/jpa/jpa_110.xsd 
http://aries.apache.org/xmlns/transactions/v1.0.0 http://aries.apache.org/schemas/transaction/transactionv10.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd 
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
>

   <service interface="org.activiti.camel.ContextProvider">
        <bean class="org.activiti.camel.SimpleContextProvider">
            <argument value="checkactiviti"/>
            <argument ref="camelContext1"/>
        </bean>
    </service>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://192.168.1.100:5432/workflow1" />
        <property name="username" value="xxx" />
        <property name="password" value="xxxx" />
    </bean>
    
    <bean id="configurationFactory" class="org.activiti.osgi.blueprint.ConfigurationFactory">
        <property name="dataSource" ref="dataSource"/>
        <property name="databaseSchemaUpdate" value="true"/>
    </bean>
    
    <bean id="configuration" factory-ref="configurationFactory"  factory-method="getConfiguration"/>
    
    <bean id="processEngineFactory" class="org.activiti.osgi.blueprint.ProcessEngineFactory" init-method="init" destroy-method="destroy">
        <property name="processEngineConfiguration" ref="configuration"/>
        <property name="bundle" ref="blueprintBundle"/>
        <property name="blueprintELResolver" ref="blueprintELResolver"/>
    </bean>
    
    <bean id="processEngine" factory-ref="processEngineFactory" factory-method="getObject"/>
    <bean id="identityService" factory-ref="processEngine" factory-method="getIdentityService"/>
    <bean id="runtimeService" factory-ref="processEngine" factory-method="getRuntimeService"/>
    <bean id="repositoryService" factory-ref="processEngine" factory-method="getRepositoryService"/>
    <bean id="blueprintELResolver" class="org.activiti.osgi.blueprint.BlueprintELResolver"/>
    
    <service ref="processEngine"  interface="org.activiti.engine.ProcessEngine"/>
    <service ref="identityService" interface="org.activiti.engine.IdentityService"/>
    <service ref="runtimeService" interface="org.activiti.engine.RuntimeService"/>
    <service ref="repositoryService" interface="org.activiti.engine.RepositoryService"/>
    
    <bean id="camel_bean" class="com.lala.activiti.CamelProcessor">
    	<property name="processEngine" ref="processEngine"/>
    </bean>
    
    <bean id="bean1" class="com.lala.bean.Bean1">
        <property name="processEngine" ref="processEngine"/>
         <property name="camelContext1" ref="camelContext1"/>
        
    </bean>
    <bean id="bean2" class="com.lala.bean.Bean2">
         <property name="processEngine" ref="processEngine"/>
       
        <property name="camelContext1" ref="camelContext1"/>
    </bean>
    <bean id="bean3" class="com.lala.bean.Bean3"></bean>


    
    <camelContext id="camelContext1" xmlns="http://camel.apache.org/schema/blueprint">
    	
        <route id="activitidemo">
            <from uri="acitivitiwg"/>
            <to uri="activiti:checkactiviti"/>
        </route>

        <route id="cool1">
            <from uri="activiti:checkactiviti:servicetask1" />
            <to uri="bean:bean1"/>
        </route>
		
        <route id="cool2">
            <from uri="activiti:checkactiviti:servicetask2?copyVariablesToProperties=true" />
            <to uri="bean:bean2"/>
        </route>
    </camelContext>
</blueprint>

并且在src\main\resources\OSGI-INF\activiti\  文件夹下面定义check.bpmn20.xml

<?xml version="1.0" encoding="UTF-8"?>
             
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 
			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
			 xmlns:activiti="http://activiti.org/bpmn" 
			 xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" 
			 xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" 
			 xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             typeLanguage="http://www.w3.org/2001/XMLSchema" 
             expressionLanguage="http://www.w3.org/1999/XPath" 
             targetNamespace="http://www.activiti.org/test">

	<process id="checkactiviti" name="自动执行例子" isExecutable="true">
		<startEvent id="startevent1" name="自动执行"></startEvent>

		<serviceTask id="servicetask1" name="一级转发" activiti:delegateExpression="${camel}"></serviceTask>
		 
		<serviceTask id="servicetask2" name="二级转发" activiti:delegateExpression="${camel}"></serviceTask>
                
                <userTask id="usertask1" name="UserTask" activiti:delegateExpression="${camel}"></userTask>
                
		<endEvent id="endevent1" name="结束"></endEvent>
		
			
		<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
		<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
                <sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="usertask1"></sequenceFlow>
		<sequenceFlow id="flow4" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>

		
	</process>

</definitions>

bean1.java

public class Bean1 implements Processor {

    private ProcessEngine processEngine;
    private CamelContext camelContext1;
    public void setProcessEngine(ProcessEngine processEngine) {
        this.processEngine = processEngine;
    }


    public void setCamelContext1(CamelContext camelContext1) {
        this.camelContext1 = camelContext1;
    }
    

    @Override
    public void process(Exchange exchange) throws Exception {
       
        exchange.getOut().setBody("sss");
        
    }

}
pom.xml需要导入依赖

 <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-camel</artifactId>
            <version>5.16</version>
            <scope>provided</scope>

</dependency>

<dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-osgi</artifactId>
            <version>5.17.0</version>
            <scope>provided</scope>
</dependency>

当然servicemix需要安装插件

<?xml version="1.0" encoding="UTF-8"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.0.0 http://karaf.apache.org/xmlns/features/v1.0.0"
>

 <feature name='features-activiti' version='1.0.0' install="auto">
<feature version='5.16.4'>activiti</feature>
 </feature> 


</features>



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值