Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
class MyRouteBean extends RouteBuilder {
 
	@Override
    public void configure() {
        from("activemq:queue:foo")
            .transacted("PROPAGATION_REQUIRED")
            .bean("transformer")
            .to("jpa:my.application.entity.Bar")
            .log("${body.id} inserted");
    }
}
 

This would be equivalent to:

Code Block
languagejava
class MyRouteBean extends RouteBuilder {

    @Inject
    @Named("PROPAGATION_REQUIRED")
    Policy required;
 
	@Override
    public void configure() {
        from("activemq:queue:foo")
            .policy(required)
            .bean("transformer")
            .to("jpa:my.application.entity.Bar")
            .log("${body.id} inserted");
    }
}
 

Transactional error handler

...

The list of supported transaction policy names is: PROPAGATION_NEVERPROPAGATION_NOT_SUPPORTED, PROPAGATION_SUPPORTSPROPAGATION_REQUIREDPROPAGATION_REQUIRES_NEW, PROPAGATION_NESTEDPROPAGATION_MANDATORY.

Transactional error handler

Camel CDI provides a transactional error handler that extends the redelivery error handler, forces a rollback whenever an exception occurs and creates a new transaction for each redelivery. Camel CDI provides the CdiRouteBuilder class that exposes the transactionErrorHandler helper method to enable quick access to the configuration, e.g.:

Code Block
languagejava
class MyRouteBean extends CdiRouteBuilder {

	@Override
    public void configure() {
        errorHandler(transactionErrorHandler()
            .setTransactionPolicy("PROPAGATION_SUPPORTS")
            .maximumRedeliveries(5)
            .maximumRedeliveryDelay(5000)
            .collisionAvoidancePercent(10)
            .backOffMultiplier(1.5));
    }
}

Auto-configured OSGi integration

...