You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

UuidGenerator

Starting with Camel 2.5, Camel supports 3rd part UUID generator. This is useful, if e.g. your messaging provider does not support UUID's with a length of 36 characters (like Websphere MQ). Another useful scenario is to use a simple counter for testing purpose. With this it is easier to correlate the exchanges in the log/debugger.

You only have to implement org.apache.camel.spi.UuidGenerator and tell Camel, that it should use your custom implementation:

Configuring from Java DSL

getContext().setUuidGenerator(new MyCustomUuidGenerator());

You should not change the UUID generator at runtime (it should only be set once)!

Configuring from Spring DSL

Camel will configure this UUID generator by doing a lookup in the Spring bean registry to find the bean of the type org.apache.camel.spi.UuidGenerator.

<bean id="activeMQUuidGenerator" class="org.apache.camel.impl.ActiveMQUuidGenerator" />

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:start" />
    <to uri="mock:result" />
  </route>
</camelContext>

Provided implementations

Camel comes with three implementations of org.apache.camel.spi.UuidGenerator:

  • org.apache.camel.impl.DefaultUuidGenerator - The default Camel UUID generator which use java.util.UUID.
  • org.apache.camel.impl.SimpleUuidGenerator - This implementation use internally a java.util.concurrent.atomic.AtomicLong and increase the ID for every call by one.
  • org.apache.camel.impl.ActiveMQUuidGenerator - This implementation use the ActiveMQ/Camel 1.x style of ID's.
  • No labels