Permalink
Browse files

SMX4-1191: Add Activiti with Camel example

git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx4/features/trunk@1353980 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 90547ed commit b61843247524cdd164bd675a05ae3422d1c40909 @gertv gertv committed Jun 26, 2012
View
5 NOTICE
@@ -9,3 +9,8 @@
This product contains software developed by
Open Participation Software for Java (http://www.ops4j.org/).
+ This software contains unmodified binary redistributions for H2 database engine (http://www.h2database.com/),
+ which is dual licensed and available under a modified version of the MPL 1.1 (Mozilla Public License)
+ or under the (unmodified) EPL 1.0 (Eclipse Public License).
+ An original copy of the license agreement can be found at: http://www.h2database.com/html/license.html
+
View
4 assemblies/apache-servicemix/src/main/filtered-resources/features.xml
@@ -319,14 +319,16 @@
<feature name="activiti" version="${activiti.version}" resolver="(obr)">
<feature version="${cxf.version}">cxf-specs</feature>
<feature version="${aries.version}">transaction</feature>
+ <feature version="${camel.version}">camel</feature>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.wsdl4j/${wsdl4j.bundle.version}</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.mybatis/${mybatis.bundle.version}</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.scripting-api-1.0/${servicemix.specs.version}</bundle>
<bundle dependency="true">mvn:commons-lang/commons-lang/${commons-lang.version}</bundle>
+ <bundle dependency="true">mvn:com.h2database/h2/${h2.version}</bundle>
<bundle>mvn:org.activiti/activiti-engine/${activiti.version}</bundle>
<bundle>mvn:org.activiti/activiti-osgi/${activiti.version}</bundle>
<bundle>mvn:org.activiti/activiti-camel/${activiti.version}</bundle>
- <bundle>mvn:org.apche.servicemix.activiti/org.apache.servicemix.activiti.config/${project.version}</bundle>
+ <bundle>mvn:org.apache.servicemix.activiti/org.apache.servicemix.activiti.config/${project.version}</bundle>
</feature>
</features>
View
146 examples/activiti/activiti-camel/README.txt
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+Activiti and Camel Example
+==========================
+
+Purpose
+-------
+This example will show you how to use Activiti inside Apache ServiceMix and how
+interact with your Activiti processes from within you Camel routes.
+
+In our example, we define a simple order process, that process the incoming orders
+and subsequently waits for its delivery. Once the delivery notification has been
+received, another bit of processing occurs before the business process ends.
+
+We use Camel routes to start new process instances and notify running processes
+about deliveries. We also use Camel routes to implement the order and delivery
+processing itself.
+
+
+Explanation
+-----------
+In the Blueprint XML file (activiti-camel.xml), we are:
+1. setting up our Camel context with our Camel routes
+2. setting up the ActivitiComponent that will allow us to interact between our business process and our Camel routes
+3. registering a ContextProvider instance to make your CamelContext available through the ${camel} expression in your
+ business process definitions files
+
+The OrderProcess.bpmn20.xml business process definition defines the BPMN definition for our process. This process is
+automatically deployed as soon as bundle is started:
+
+ start --> processOrder --> waitForDelivery --> processDelivery --> end
+
+The ActivitRouteBuilder class defines 4 routes:
+1. The first route will process files in the var/activiti-camel/order and for every file, a new business process instance
+ will be started. The Camel route will also assign a business key to the new process (the file name) and add a few
+ extra variables to the process.
+2. The second route will process files in the var/activiti-camel/delivery and once again uses the file name to notify
+ running processes about order deliveries.
+3. The third route will be triggered by the BPMN process when it executes its 'processOrder' service task.
+4. The fourth route will be triggered by the BPMN process when it executes its 'processDelivery' service task.
+
+
+Prerequisites for Running the Example
+-------------------------------------
+1. You must have the following installed on your machine:
+
+ - JDK 1.6 or higher
+
+ - Maven 3.0.2 or higher (for building)
+
+ For more information, see the README in the top-level examples
+ directory.
+
+2. Start ServiceMix by running the following command:
+
+ <servicemix_home>/bin/servicemix (on UNIX)
+ <servicemix_home>\bin\servicemix (on Windows)
+
+
+Running the Example
+-------------------
+To install and run the example where you build the example bundle
+yourself, complete the following steps:
+
+1. Before being able to run this example, you have to install some additional
+ features into the container first to add support for the Activiti.
+
+ features:install activiti
+
+2. Build the example by opening a command prompt, changing directory to
+ examples/activiti/activiti-camel (this example) and entering the following Maven
+ command:
+
+ mvn clean install
+
+ If all of the required OSGi bundles are available in your local Maven
+ repository, the example will build very quickly. Otherwise it may
+ take some time for Maven to download everything it needs.
+
+ The mvn install command builds the example deployment bundle and
+ copies it to your local Maven repository and to the target directory
+ of this example.
+
+3. Install the example by entering the following command in
+ the ServiceMix console:
+
+ osgi:install mvn:org.apache.servicemix.examples/activiti-camel/${project.version}
+
+4. Once the bundle has been started, you will see a var/activiti-camel/order directory
+ under your ServiceMix installation directory. If you create files in that directory,
+ you will see output like this appearing in the log file.
+
+ Processing order 1508 created on 2012-06-26 11:50:19
+ original message: <message/>
+ Process to handle incoming order file has been started (process instance id 14808)
+
+ At that point, you have a running process instance for order 1508 that is waiting for delivery.
+
+5. To notify the process about the delivery, you have to create a file with the same name
+ in the var/activiti-camel/delivery directory. For example, to signal the delivery of order 1508,
+ create a file named var/activiti-camel/delivery/1508. As soon as the Camel route picks up the
+ file, you will see more output from the business process:
+
+ Notifying process about delivery for order 1508
+ Processing delivery for order 1508 created on 2012-06-26 11:50:19
+ original message: <message/>
+
+
+Stopping and Uninstalling the Example
+-------------------------------------
+First, find the bundle id for the deployed example bundle by doing
+
+ osgi:list
+
+and looking for a line that looks like this one
+
+ [ 317] [Active ] [Created ] [ ] [ 80] Apache ServiceMix :: Examples :: Activiti :: Activiti Camel (${project.version})
+
+In the above case, the bundle id would be 317
+
+
+To stop the example, enter the following command in the ServiceMix
+console:
+
+ osgi:stop <bundle_id>
+
+
+To uninstall the example, enter one of the following commands in
+the ServiceMix console:
+
+ osgi:uninstall <bundle_id>
View
63 examples/activiti/activiti-camel/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>activiti-examples</artifactId>
+ <groupId>org.apache.servicemix.examples</groupId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>activiti-camel</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache ServiceMix :: Examples :: Activiti :: Activiti Camel</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.activiti</groupId>
+ <artifactId>activiti-camel</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Description>${project.description}</Bundle-Description>
+ <Import-Package>*</Import-Package>
+ <Private-Package>org.apache.servicemix.examples.activiti</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
View
95 ...iti-camel/src/main/java/org/apache/servicemix/examples/activiti/ActivitiRouteBuilder.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.examples.activiti;
+
+import org.apache.camel.Body;
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+import org.apache.camel.Header;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.language.Simple;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.activiti.camel.ActivitiProducer.PROCESS_KEY_PROPERTY;
+
+/**
+ * Camel routes that interact with the business process defined in the
+ * OSGI-INF/activiti/OrderProcess.bpmn20.xml file
+ */
+public class ActivitiRouteBuilder extends RouteBuilder {
+
+ private final Helper helper = new Helper();
+
+ @Override
+ public void configure() throws Exception {
+ /*
+ * This route will start a new OrderProcess instance. Using the PROCESS_KEY_PROPERTY, we are assigning a
+ * business key to our process to allow for easier correlation in later processing steps. We are also
+ * sending a Map containing additional variables to add to the process instance.
+ */
+ from("file:var/activiti-camel/order")
+ .setBody(bean(helper))
+ .setProperty(PROCESS_KEY_PROPERTY, simple("file:name"))
+ .to("activiti:OrderProcess")
+ .log("Process to handle incoming order file has been started (process instance id ${body})");
+
+ /*
+ * This route will notify a running OrderProcess of an order delivery event. Here too, we are setting the
+ * PROCESS_KEY_PROPERTY to correlate the delivery message with right order process instance.
+ */
+ from("file:var/activiti-camel/delivery")
+ .log("Notifying process about delivery for order ${file:name}")
+ .setProperty(PROCESS_KEY_PROPERTY, simple("file:name"))
+ .to("activiti:OrderProcess:receiveDelivery");
+
+ /*
+ * The BPMN process can also trigger Camel routes as part of the process. In these routes, the variables that
+ * you added to the process are available as Exchange properties. The next two routes will be triggered while
+ * processing the order and the order delivery.
+ */
+ from("activiti:OrderProcess:processOrder")
+ .log("Processing order ${property.orderid} created on ${property:timestamp}")
+ .log(" original message: ${property.message}");
+
+ from("activiti:OrderProcess:processDelivery")
+ .log("Processing delivery for order ${property.orderid} created on ${property:timestamp}")
+ .log(" original message: ${property.message}");
+ }
+
+ /*
+ * A few helper methods used for routing
+ */
+ public static final class Helper {
+
+ /*
+ * This method will extract information from the Exchange (using Camel annotations) and put them in a
+ * Map that will be used for setting up the process' variables.
+ */
+ @Handler
+ public Map getProcessVariables(@Body String body,
+ @Header(Exchange.FILE_NAME) String filename,
+ @Simple("${date:now:yyyy-MM-dd kk:mm:ss}") String timestamp) {
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("message", body);
+ variables.put("orderid", filename);
+ variables.put("timestamp", timestamp);
+ return variables;
+ }
+ }
+}
View
44 ...ples/activiti/activiti-camel/src/main/resources/OSGI-INF/activiti/OrderProcess.bpmn20.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<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="OrderProcess">
+
+ <startEvent id="start"/>
+
+ <sequenceFlow id="flow1" sourceRef="start" targetRef="processOrder"/>
+
+ <serviceTask id="processOrder" activiti:delegateExpression="${camel}"/>
+
+ <sequenceFlow id="flow2" sourceRef="processOrder" targetRef="receiveDelivery"/>
+
+ <receiveTask id="receiveDelivery" name="Wait for Delivery" />
+
+ <sequenceFlow id="flow3" sourceRef="receiveDelivery" targetRef="processDelivery"/>
+
+ <serviceTask id="processDelivery" activiti:delegateExpression="${camel}"/>
+
+ <sequenceFlow id="flow4" sourceRef="processDelivery" targetRef="end"/>
+
+ <endEvent id="end"/>
+
+ </process>
+
+</definitions>
View
58 examples/activiti/activiti-camel/src/main/resources/OSGI-INF/blueprint/activiti-camel.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:camel="http://camel.apache.org/schema/blueprint">
+
+ <!--
+ This Camel context contains the routes that interact with our BPMN process
+ -->
+ <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/blueprint">
+ <packageScan>
+ <package>org.apache.servicemix.examples.activiti</package>
+ </packageScan>
+ </camelContext>
+
+ <!--
+ Obtain a reference to Activiti's RuntimeService - this reference will automatically
+ be picked up by the subsequent Activiti Camel component definition
+ -->
+ <reference id="runtimeService" interface="org.activiti.engine.RuntimeService" />
+
+ <!--
+ In Activiti 5.9, the ActivitiComponent does not have a default constructor, so you
+ have to explicitly instantiate it here
+
+ This will not be necessary any more in later versions of Activiti
+ -->
+ <bean id="activiti" class="org.activiti.camel.ActivitiComponent">
+ <argument ref="camelContext" />
+ </bean>
+
+ <!--
+ Register a context provider to link the Camel context to the OrderProcess definition.
+ Doing this will allow your BPMN process to communicate with the Camel routes using the
+ ${camel} expression
+ -->
+ <service interface="org.activiti.camel.ContextProvider">
+ <bean class="org.activiti.camel.SimpleContextProvider">
+ <argument value="OrderProcess"/>
+ <argument ref="camelContext"/>
+ </bean>
+ </service>
+
+</blueprint>
View
38 examples/activiti/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix.examples</groupId>
+ <artifactId>examples</artifactId>
+ <version>4.5.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.servicemix.examples</groupId>
+ <artifactId>activiti-examples</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache ServiceMix :: Examples :: Activiti</name>
+
+ <modules>
+ <module>activiti-camel</module>
+ </modules>
+
+</project>
View
1 examples/pom.xml
@@ -35,6 +35,7 @@
<modules>
<module>activemq</module>
+ <module>activiti</module>
<!-- <module>akka</module> commented out now until Akka OSGi bundle are available in a repo -->
<module>camel</module>
<module>cxf</module>
View
1 pom.xml
@@ -209,6 +209,7 @@
<commons-logging.version>1.1.1</commons-logging.version>
<drools.version>5.1.1</drools.version>
<groovy.version>1.8.3</groovy.version>
+ <h2.version>1.3.167</h2.version>
<javax.mail.version>1.4.4</javax.mail.version>
<jaxp-ri.version>1.4.4</jaxp-ri.version>
<xerces.version>2.11.0</xerces.version>

0 comments on commit b618432

Please sign in to comment.