Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

CorrelationId for Apache Camel with Spring

mariuszs edited this page Nov 6, 2014 · 2 revisions

Description

If you are using Apache Camel routes in your service there is now possibility to handle correlationId in received/sent message header.

For all incoming messages correlationId value will be taken from corresponding header and set in current thread. In case there is no such header field, a new one will be created with correlationId generated. On the other hand when a message with no correlationId header set is going to be sent the proper header field will be provided for it automatically.

NOTE!!

Current solution does not support routes defined in XML files.

Example of usage

There are two things required to have this working: configuration enabled (see Module configuration below) and Camel route should be defined in org.apache.camel.builder.RouteBuilder implementation.

The implementation of the builder is straightforward:

class MyRouteBuilder extends RouteBuilder {
    @Override
    void configure() throws Exception {
        from('direct:start').to('my:cool:endpoint').routeId('route-1')
    }
}

Now you just need to expose the builder as a Spring bean in configuration of your service and that's it.

Module configuration

If you want to use only this module just add a dependency:

repositories {
    jcenter()
}

dependencies {
    compile 'com.ofg:micro-infra-spring-camel:0.6.0'
}

and enable this via annotation:

@Configuration
@EnableCorrelationIdForCamel
class MyWebAppConfiguration {
}