Integrating Activiti BPM with JMS

motif

Activiti is a light-weight workflow and Business Process Management () Platform targeted at business people, developers and system admins. However, its standard version doesn’t allow you to integrate with your existing enterprise technologies (e.g. your broker). In this post we will briefly explain how to integrate Activiti with using Mule’s Activiti Module.

First, you will need to run Activiti in embedded mode inside your Mule application; it is pretty similar to run Activiti inside Spring. An example configuration is shown next; you will need to define your processEngineConfiguration and the service beans you can obtain from it:

    <spring:bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
    	<spring:property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
    	<spring:property name="jdbcDriver" value="org.h2.Driver" />
    	<spring:property name="jdbcUsername" value="sa" />
    	<spring:property name="jdbcPassword" value="" />
        <spring:property name="databaseSchemaUpdate" value="true" />
        <spring:property name="jobExecutorActivate" value="false" />
    </spring:bean>

    <spring:bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <spring:property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </spring:bean>

    <spring:bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <spring:bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    <spring:bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    <spring:bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />

Then you will also need to define your JMS broker; in our case we will use Active MQ:

    <jms:activemq-connector name="jmsConnector" />

Finally, your Mule’s Activiti connector:

    <activiti:connector name="activitiServer" version="5.5"
        repositoryService-ref="repositoryService"
        runtimeService-ref="runtimeService"
        taskService-ref="taskService"
        historyService-ref="historyService" />

We are ready!
For our example, let’s suppose we have a process for managing orders that waits for the approval of a manager. The manager approves them by submitting a message to the JMS queue approveQueue. To resolve which process needs to be approved the message must contain the process id and the username which will be set in the approvedBy variable. For the sake of conciseness, we will create the process from Mule as shown next:

    <flow name="create-process">
        <vm:inbound-endpoint path="in" exchange-pattern="request-response" />
        <activiti:create-process parametersExpression="#[header:INBOUND:createProcessParameters]" />
    </flow>

This process will start and wait for a message in the JMS queue to signal it. This can be easily solved from the Mule side by specifying a flow that reads from a JMS queue, sets the variable approvedBy and signal the process as shown next:

    <flow name="approve-flow">
        <jms:inbound-endpoint queue="approveQueue" />
        <activiti:set-variable executionIdExpression="#[groovy:payload.id]" 
            variableExpression="#[string:approvedBy]" valueExpression="#[header:INBOUND:username]" />
        <activiti:signal executionIdExpression="#[groovy:payload.id]" />
    </flow>

Want to see the full example? Check our git hub repository for Activiti examples. Hope you want to start integrating Activiti with your existing enterprise environment using Mule’s Activiti Module and I look forward to your comments.


We'd love to hear your opinion on this post


4 Responses to “Integrating Activiti BPM with JMS”

  1. Great post! How can this integration module send message to a JMS queue as a send task defined in the activiti bpmn2 process?

  2. Hi,
    You can send messages to any mule endpoint using the approach shown in http://www.webspeclanguage.org/esteban/2011/05/did-your-business-people-fall-in-love-with-salesforce-if-so-integrate-with-it-from-activiti/

    It will be available in Activiti 5.6!
    Cheers
    Esteban

  3. 3.1.0
    5.8
    3.2.0

    muleforge-repo
    MuleForge Repository
    http://repository.muleforge.org
    default

    Gives me errors.

    27/11/11 20:06:15 GMT: Maven Builder: AUTO_BUILD
    27/11/11 20:06:20 GMT: Refreshing [/mule-module-activiti-jms/pom.xml]
    27/11/11 20:06:21 GMT: Missing artifact org.activiti:activiti-engine:jar:5.8:compile
    27/11/11 20:06:21 GMT: Missing artifact org.apache.commons:commons-email:jar:1.2:compile
    27/11/11 20:06:21 GMT: Missing artifact javax.mail:mail:jar:1.4.1:compile
    27/11/11 20:06:21 GMT: Missing artifact javax.activation:activation:jar:1.1:compile

  4. Sorry, to expand….I’m trying to use your configurations in your github project…and it gives me the errors I showed above.