camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject [DISCUSS - Camel 2.0]- Synchronization (UnitOfWork callbacks) and needed syntax DSL sugar
Date Tue, 12 May 2009 08:20:47 GMT

Now that the we had an internal API cleanup and the new Async API in place.
I thought I will take a look at the UnitOfWork and its synchronization hooks.

About synchronization
org.apache.camel.spi.Synchronization is an interface defining 2
methods for callbacks when an Exchange is done.
- 1 callback for complete
- 1 callback for failure

This is really great and nice. What end users and Camel internally
actually need.

What you can do with this is for instance as some end users have
requirements for is to be able to send an email in case something goes
Or log when a processing of the message is complete / finished etc.

Today you can do this with error handling and eg route to an additonal
endpoint when the route is at its end.
But what we would like is nice DSL syntax for this and the feature
implemented in a single logical execution wihtin Camel itself.

Some of the basis idea for the UnitOfWork constitutes this. That is a
context that abstracts the work an exchange undertakes during routing.
UnitOfWork is already integrated with  the Synchronization API and
thus it invokes the callback if any is registered.

But to use it today you need to access and register the callbacks on
the Exchange and thus you usually need a Processor and do the wiring
in Java code.
The code is not clean and nice so what is needed is some syntax sugar in the DSL

Syntax Sugar in DSL
I have started experimenting with new DSL for registering callbacks.
But I am in doubt of naming and such.

For example I have:

        return new RouteBuilder() {
            public void configure() throws Exception {
                Processor complete = new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        assertEquals("Bye World",
                        SynchronizeTest.this.complete = true;

                    .transform(constant("Bye World"))

This was just a quick prototype to allow to register a Processor with
the completion callback. Notice that we use the .synchronize DSL

I am wondering what good names would be
- synchronize
- onComplete
- onFailure
- onDone (eg for a single DSL keyword for both complete/failure)

For instance with onComplete:
                    .transform(constant("Bye World"))

Not just a processor
The processor thingy was just an experiment the idea is to be able to
route, eg to a bean for POJO, log for logging, smtp for email etc.

For instance something like this:

                    // end to indicate end of onFailure route
                    // this is the original route that we route to
after from direct:start
                    .transform(constant("Bye World"))

And it should be a route by itself just like the intercept() so you
can route it to multiple destinations and do other work as you like.

And we could consider having scope as well. So you can define
synchronization hooks at global level, so they apply for all.

Any thoughts?

Claus Ibsen
Apache Camel Committer

Open Source Integration:
Apache Camel Reference Card:
Interview with me:

View raw message