|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +Activiti and Camel Example |
| 19 | +========================== |
| 20 | + |
| 21 | +Purpose |
| 22 | +------- |
| 23 | +This example will show you how to use Activiti inside Apache ServiceMix and how |
| 24 | +interact with your Activiti processes from within you Camel routes. |
| 25 | + |
| 26 | +In our example, we define a simple order process, that process the incoming orders |
| 27 | +and subsequently waits for its delivery. Once the delivery notification has been |
| 28 | +received, another bit of processing occurs before the business process ends. |
| 29 | + |
| 30 | +We use Camel routes to start new process instances and notify running processes |
| 31 | +about deliveries. We also use Camel routes to implement the order and delivery |
| 32 | +processing itself. |
| 33 | + |
| 34 | + |
| 35 | +Explanation |
| 36 | +----------- |
| 37 | +In the Blueprint XML file (activiti-camel.xml), we are: |
| 38 | +1. setting up our Camel context with our Camel routes |
| 39 | +2. setting up the ActivitiComponent that will allow us to interact between our business process and our Camel routes |
| 40 | +3. registering a ContextProvider instance to make your CamelContext available through the ${camel} expression in your |
| 41 | + business process definitions files |
| 42 | + |
| 43 | +The OrderProcess.bpmn20.xml business process definition defines the BPMN definition for our process. This process is |
| 44 | +automatically deployed as soon as bundle is started: |
| 45 | + |
| 46 | + start --> processOrder --> waitForDelivery --> processDelivery --> end |
| 47 | + |
| 48 | +The ActivitRouteBuilder class defines 4 routes: |
| 49 | +1. The first route will process files in the var/activiti-camel/order and for every file, a new business process instance |
| 50 | + will be started. The Camel route will also assign a business key to the new process (the file name) and add a few |
| 51 | + extra variables to the process. |
| 52 | +2. The second route will process files in the var/activiti-camel/delivery and once again uses the file name to notify |
| 53 | + running processes about order deliveries. |
| 54 | +3. The third route will be triggered by the BPMN process when it executes its 'processOrder' service task. |
| 55 | +4. The fourth route will be triggered by the BPMN process when it executes its 'processDelivery' service task. |
| 56 | + |
| 57 | + |
| 58 | +Prerequisites for Running the Example |
| 59 | +------------------------------------- |
| 60 | +1. You must have the following installed on your machine: |
| 61 | + |
| 62 | + - JDK 1.6 or higher |
| 63 | + |
| 64 | + - Maven 3.0.2 or higher (for building) |
| 65 | + |
| 66 | + For more information, see the README in the top-level examples |
| 67 | + directory. |
| 68 | + |
| 69 | +2. Start ServiceMix by running the following command: |
| 70 | + |
| 71 | + <servicemix_home>/bin/servicemix (on UNIX) |
| 72 | + <servicemix_home>\bin\servicemix (on Windows) |
| 73 | + |
| 74 | + |
| 75 | +Running the Example |
| 76 | +------------------- |
| 77 | +To install and run the example where you build the example bundle |
| 78 | +yourself, complete the following steps: |
| 79 | + |
| 80 | +1. Before being able to run this example, you have to install some additional |
| 81 | + features into the container first to add support for the Activiti. |
| 82 | + |
| 83 | + features:install activiti |
| 84 | + |
| 85 | +2. Build the example by opening a command prompt, changing directory to |
| 86 | + examples/activiti/activiti-camel (this example) and entering the following Maven |
| 87 | + command: |
| 88 | + |
| 89 | + mvn clean install |
| 90 | + |
| 91 | + If all of the required OSGi bundles are available in your local Maven |
| 92 | + repository, the example will build very quickly. Otherwise it may |
| 93 | + take some time for Maven to download everything it needs. |
| 94 | + |
| 95 | + The mvn install command builds the example deployment bundle and |
| 96 | + copies it to your local Maven repository and to the target directory |
| 97 | + of this example. |
| 98 | + |
| 99 | +3. Install the example by entering the following command in |
| 100 | + the ServiceMix console: |
| 101 | + |
| 102 | + osgi:install mvn:org.apache.servicemix.examples/activiti-camel/${project.version} |
| 103 | + |
| 104 | +4. Once the bundle has been started, you will see a var/activiti-camel/order directory |
| 105 | + under your ServiceMix installation directory. If you create files in that directory, |
| 106 | + you will see output like this appearing in the log file. |
| 107 | + |
| 108 | + Processing order 1508 created on 2012-06-26 11:50:19 |
| 109 | + original message: <message/> |
| 110 | + Process to handle incoming order file has been started (process instance id 14808) |
| 111 | + |
| 112 | + At that point, you have a running process instance for order 1508 that is waiting for delivery. |
| 113 | + |
| 114 | +5. To notify the process about the delivery, you have to create a file with the same name |
| 115 | + in the var/activiti-camel/delivery directory. For example, to signal the delivery of order 1508, |
| 116 | + create a file named var/activiti-camel/delivery/1508. As soon as the Camel route picks up the |
| 117 | + file, you will see more output from the business process: |
| 118 | + |
| 119 | + Notifying process about delivery for order 1508 |
| 120 | + Processing delivery for order 1508 created on 2012-06-26 11:50:19 |
| 121 | + original message: <message/> |
| 122 | + |
| 123 | + |
| 124 | +Stopping and Uninstalling the Example |
| 125 | +------------------------------------- |
| 126 | +First, find the bundle id for the deployed example bundle by doing |
| 127 | + |
| 128 | + osgi:list |
| 129 | + |
| 130 | +and looking for a line that looks like this one |
| 131 | + |
| 132 | + [ 317] [Active ] [Created ] [ ] [ 80] Apache ServiceMix :: Examples :: Activiti :: Activiti Camel (${project.version}) |
| 133 | + |
| 134 | +In the above case, the bundle id would be 317 |
| 135 | + |
| 136 | + |
| 137 | +To stop the example, enter the following command in the ServiceMix |
| 138 | +console: |
| 139 | + |
| 140 | + osgi:stop <bundle_id> |
| 141 | + |
| 142 | + |
| 143 | +To uninstall the example, enter one of the following commands in |
| 144 | +the ServiceMix console: |
| 145 | + |
| 146 | + osgi:uninstall <bundle_id> |
0 commit comments