Reading Time: 3 minutes

Activiti is a light-weight workflow and Business Process Management (BPM) 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 JMS broker). In this post we will briefly explain how to integrate Activiti with JMS 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 id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <spring:property name="processEngineConfiguration" ref="processEngineConfiguration" />

    <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" />

latest report
Learn why we are the Leaders in API management and iPaaS

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"
        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]" />

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="#[]" 
            variableExpression="#[string:approvedBy]" valueExpression="#[header:INBOUND:username]" />
        <activiti:signal executionIdExpression="#[]" />

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.