cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating Activiti with Apache Camel

mproch
Champ in-the-making
Champ in-the-making
Hello,
I created simple component for integration of Activiti with Apache Camel (http://camel.apache.org/).

There are two use cases:
- implementing receive tasks using camel, so that one can write camel route:
from("direct:a").to("activiti:simpleProcess:receive");
which signals activity with id receive in process simpleProcess i.e.
<receiveTask id="receive" name="Wait State" />
- implementing service tasks using camel, so that one can write:
from("activiti:simpleProcess:serviceTask").setBody().property("var1").
                to("mock:service1");
and in process code sth like:
<serviceTask id="serviceTask" activiti:delegateExpression="${camel}"/>
(where var1 is name of process variable).

In the future I hope it would be possible to integrate it with OSGI deployment, especially when  http://jira.codehaus.org/browse/ACT-324 is resolved. It would be also good to find some nicer way of invoking camel from activiti process.

The code is on github: https://github.com/mproch/camel-activiti.
I would be happy to contribute it to Activiti.

what do you think about it?
maciek
18 REPLIES 18

tombaeyens
Champ in-the-making
Champ in-the-making
sorry for the late reply.  can you elaborate on what exactly you want to contribute to activiti?
fyi: we don't know camel, but we're interested in the integration.

mproch
Champ in-the-making
Champ in-the-making
Thx for answer.

1. Apache Camel - http://camel.apache.org/
Camel is a  integration framework based on known Enterprise Integration Patterns with powerful Bean Integration.
It's somewhat similar to Mule, the main differences are:
  a) Camel is more a library than container - it can be embedded in virtually every environment - one of most common usages is acting as EIP implementation for Apache Servicemix ESB - http://servicemix.apache.org/home.html, or Apache Karaf OSGi container - http://karaf.apache.org/
  b) Camel's strong point is Java DSL, which allows for easy definition of integration routes (called flows in Mule)
What's more:
  a) It's v. easy to add new components (called modules/transports in Mule) - there are more than 70 I guess  - http://camel.apache.org/components.html.
      Components are autodiscovered on classpath, and identified by uri (e.g. file:///tmp - identifies endpoint reading or writing files to folder /tmp, jsm:topic:myTopic - identifies endpoint publishing or subscribing to myTopic)
  b) It's very easy to integrate Camel with spring or OSGi Blueprint

2. What we want to doOur main use case is to be able to deploy Activiti processes in OSGi container. We use mainly Camel for our integration needs, so we thought it'd be nice to be able to perform integration (both calling services from process, and processes waiting for messages from external systems) by custom Camel component.

3. How would it work?
The process would be deployed as a OSGi bundle, together with appropriate camel context, using OSGi deployment model currently available in Activiti.
https://github.com/mproch/activitiCamelKarafSample/tree/master/process/src/main - here is sample project structure.

a) setup
This part is a bit tricky.
First, you have to create CamelBehaviour class, which has to know which camel context (there could be many for many processes) should be invoked.
Here: https://github.com/mproch/camel-activiti/blob/master/sample/src/main/resources/camel-activiti-contex... is the example for monolithic environment, in OSGi context one has to use OSGi services,
as it's done here:
https://github.com/mproch/activitiCamelKarafSample/blob/master/bundle/src/main/resources/OSGI-INF/bl..., https://github.com/mproch/activitiCamelKarafSample/blob/master/process/src/main/resources/META-INF/s.... For OSGi example I had to do some extesion of activiti-osgi to be able to use blueprint beans in activiti expressions, btw.

b) invoking Camel route from ServiceTask.
In process code, it's as simple as adding
<serviceTask id="serviceTask" activiti:delegateExpression="${camel}"/>
Then CamelBehaviour is responsible for finding Camel route starting with
from("activiti:camelProcess:serviceTask")….)(camelProcess is the processName). Exchange is created with empty body, and process variable values as properties (maybe some better solution is needed), and passed to the route, e.g.

from("activiti:camelProcess:serviceTask")
          .to("logSmiley Tonguel.touk")
          .setBody().property("var1")
          .to("file:///tmp/activiti/serviceTask");
will log contents to 'pl.touk' log appender and then create file in /tmp/activiti/serviceTask, with value of process variable var1 as content.

c) Invoking process by camel.
When process is in receive node:
<receiveTask id="receive" name="Wait State"/>it can be invoked (signaled) by following camel route:

         from( "file:///tmp/activiti/receive")
                 .convertBodyTo(String.class)
                 .setProperty("PROCESS_KEY_PROPERTY").xpath("//@key")
                 .to("activiti:camelProcess:receive");
It scans /tmp/activiti/receive directory. When file appears, it's parsed as XML and attribute key is set as process business key. Then Camel component looks for process instance of camelProcess with this key,
waiting in activity named receive. Then it signals this process, it also passes exchange properties as process variables (probably need some better solution).

Summary:
This component is not a rocket science, especially configuration is slightly awkward in OSGi environment, but it enables us to leverage power of Camel in Activiti. Guess it would serve some similar role as Mule integration, but for Apache Camel users, which are also quite numerous Smiley Wink

davsclaus
Champ in-the-making
Champ in-the-making
sorry for the late reply.  can you elaborate on what exactly you want to contribute to activiti?
fyi: we don't know camel, but we're interested in the integration.

Hi Tom

What do you mean with you don't know Camel? We spoke at the Devoxx 2010 conference Smiley Happy You and Tijs came by the FuseSource booth.

I had a look at the activiti-camel component and it seems good work.

Maciek also posted on the Camel forum
http://camel.465427.n5.nabble.com/Integrating-camel-with-activiti-tp3331707p3331707.html

So we are talking about where the component should live. Obviously we can host it at Apache Camel.
But I wonder the Activiti team plans to host integrations to 3rd party as well? If so maybe this component is better hosted at Acitivi.


/Claus Ibsen
http://davsclaus.blogspot.com/

gnodet
Champ in-the-making
Champ in-the-making
If Maciek had not worked on the the Camel component, it was on my todo list for activiti anyway, but I'm glad it's done.
I think it would make sense to host it in Activiti …

agoncal
Champ in-the-making
Champ in-the-making
Hi Maciek,

First of all a little disclaimer : I've just discovered Camel and don't know much about Activiti. This being said, here is my use case.

The project I'm currently working on uses Camel. There are plenty of Camel routes, all completely stateless and it works fine. Now we need to go further and we are talking about workflows : we need to take some of these routes, link them together, know at which step of the workflow an error occurred… and so one. So basically we need to orchestrate our Camel routes.

Would your component allow this kind of things ? Can I use Activity processes to invoke Camel routes in a seamless way ? In our use case I still don't see the inverse conversation (Camel routes accessing Activity) but I definitely need Activity to orchestrate Camel.

Thanks,
Antonio

richardketteler
Champ in-the-making
Champ in-the-making
+1 for having Activiti/Camel integration. With Mule and Spring Integration support in the pipeline it makes sense to also add Camel integration. Then Activiti will have support for three leading open source integration platforms: Mule, Spring Integration and Camel.

trademak
Star Contributor
Star Contributor
Hi,

This is great stuff!
I think this would be a good addition to the Activiti framework.
I'll have to play a little bit with the code to get a really good grasp on it, but this sure looks very promising!

Best regards,

tombaeyens
Champ in-the-making
Champ in-the-making
Looks very interesting and promising indeed. 

We're certainly open to accept all code in our codebase which is appropriate to be included in Activiti.  Ideally one contributor would take the lead and tries to find consensus.   There seem to be multiple people interested in contributing this.  Who all is volunteering to lead this Activiti code base part of the Activiti-Camel integration?

My guess would be that the Activiti-to-Camel integration should be contributed to Activiti.  Ideally that would be a service task that calls out to Camel.

I would think that the camel routes that call out to Activiti would be best contributed to the camel project.

Does all this make sense?

I don't yet see the value of OSGi deployment of processes.  As the process instances live in the DB.  And the process instances have a reference to the process definition.  If the process definition lives on the classpath (or in this case as an osgi bundle) then the process instance can get easier out of sync with their process definition.  And this gets even more tricky in cluster situations.  If someone wants to contribute OSGi deployment of business archives or processes, I would like to get a better understanding of why that is considered beneficial over the storage of business archives in the DB as we do now.

tombaeyens
Champ in-the-making
Champ in-the-making
…one more thing: if you think that it's best to host the camel routes code also at Activiti, I'm definitely OK with that!