Spring Boot

Since Camel 2.15

Spring Boot component provides auto-configuration for Apache Camel. Our opinionated auto-configuration of the Camel context auto-detects Camel routes available in the Spring context and registers the key Camel utilities (like producer template, consumer template and the type converter) as beans.

Maven users will need to add the following dependency to their pom.xml in order to use this component:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot</artifactId>
    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
</dependency>

camel-spring-boot jar comes with the spring.factories file, so as soon as you add that dependency into your classpath, Spring Boot will automatically auto-configure Camel for you.

Camel Spring Boot Starter

Since Camel 2.17

Apache Camel ships a Spring Boot Starter module that allows you to develop Spring Boot applications using starters. There is a sample application in the source code also.

To use the starter, add the following to your spring boot pom.xml file:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
</dependency>

Then you can just add classes with your Camel routes such as:

package com.example;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("timer:foo").to("log:bar");
    }
}

Then these routes will be started automatically.

You can customize the Camel application in the application.properties or application.yml file.

Spring Boot Auto-Configuration

When using spring-boot with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-spring-boot-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>

The component supports 142 options, which are listed below.

Name Description Default Type

camel.cloud.enabled

Global option to enable/disable Camel cloud support, default is true.

true

Boolean

camel.cloud.load-balancer.enabled

Global option to enable/disable Camel cloud load balancer, default is true.

true

Boolean

camel.cloud.service-call.component

The Camel component to use for calling the service. The default is http component.

String

camel.cloud.service-call.default-load-balancer

Determine if the default load balancer should be used instead of any auto discovered one.

false

Boolean

camel.cloud.service-call.expression

The expression to use.

String

camel.cloud.service-call.expression-language

The expression language to use, default is ref.

ref

String

camel.cloud.service-call.load-balancer

A reference to the org.apache.camel.cloud.ServiceLoadBalancer to use.

String

camel.cloud.service-call.service-chooser

A reference to the org.apache.camel.cloud.ServiceChooser to use.

String

camel.cloud.service-call.service-discovery

A reference to the org.apache.camel.cloud.ServiceDiscovery to use.

String

camel.cloud.service-call.service-filter

A reference to the org.apache.camel.cloud.ServiceFilter to use.

String

camel.cloud.service-call.uri

The uri of the endpoint to send to. The uri can be dynamic computed using the simple language expression.

String

camel.cloud.service-chooser.enabled

Global option to enable/disable Camel cloud service chooser, default is true.

true

Boolean

camel.cloud.service-discovery.configurations

Configure the service discovery rules.

Map

camel.cloud.service-discovery.enabled

Global option to enable/disable Camel cloud service discovery, default is true.

true

Boolean

camel.cloud.service-discovery.services

Configure service discoveries.

Map

camel.cloud.service-filter.blacklist

Configure service filter blacklists.

Map

camel.cloud.service-filter.configurations

Configure the service filtering rules.

Map

camel.cloud.service-filter.enabled

Global option to enable/disable Camel cloud service filter, default is true.

true

Boolean

camel.cloud.service-registry.enabled

Configure if service registry should be enabled or not, default true.

true

Boolean

camel.cloud.service-registry.service-host

Configure the service listening address.

String

camel.clustered.controller.cluster-service

The cluster service.

CamelClusterService

camel.clustered.controller.enabled

Global option to enable/disable Camel clustered route controller, default is false.

false

Boolean

camel.clustered.controller.initial-delay

Set the amount of time (in millis) the route controller should wait before to start the routes after the camel context is started or after the route is initialized if the route is created after the camel context is started.

String

camel.clustered.controller.namespace

The default namespace.

String

camel.clustered.controller.routes

Routes configuration.

Map

camel.component.enabled

Global option to enable/disable component auto-configuration, default is true.

true

Boolean

camel.component.properties.auto-discover-properties-sources

Whether to automatically discovery instances of PropertiesSource from registry and service factory.

true

Boolean

camel.component.properties.default-fallback-enabled

If false, the component does not attempt to find a default for the key by looking after the colon separator.

true

Boolean

camel.component.properties.encoding

Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented by java.util.Properties#load(java.io.InputStream)

String

camel.component.properties.environment-variable-mode

Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use OS environment variables if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode

2

Integer

camel.component.properties.ignore-missing-location

Whether to silently ignore if a location cannot be located, such as a properties file not found.

false

Boolean

camel.component.properties.initial-properties

Sets initial properties which will be used before any locations are resolved. The option is a java.util.Properties type.

String

camel.component.properties.location

A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.

String

camel.component.properties.override-properties

Sets a special list of override properties that take precedence and will use first, if a property exist. The option is a java.util.Properties type.

String

camel.component.properties.properties-parser

To use a custom PropertiesParser. The option is a org.apache.camel.component.properties.PropertiesParser type.

String

camel.component.properties.system-properties-mode

Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use system properties if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode

2

Integer

camel.dataformat.enabled

Global option to enable/disable dataformat auto-configuration, default is true.

true

Boolean

camel.health.check.routes.enabled

Global option to enable/disable Camel extended health check for routes, default is false.

false

Boolean

camel.health.check.routes.threshold

General health check configurations.

Map

camel.health.check.routes.thresholds.exchanges-failed

Number of failed exchanges.

Long

camel.health.check.routes.thresholds.exchanges-inflight

Number of inflight exchanges.

Long

camel.health.check.routes.thresholds.external-redeliveries

Number of external initiated redeliveries (such as from JMS broker).

Long

camel.health.check.routes.thresholds.last-processing-time.failures

The threshold of number of failures.

Integer

camel.health.check.routes.thresholds.last-processing-time.threshold

The threshold value.

String

camel.health.check.routes.thresholds.max-processing-time.failures

The threshold of number of failures.

Integer

camel.health.check.routes.thresholds.max-processing-time.threshold

The threshold value.

String

camel.health.check.routes.thresholds.mean-processing-time.failures

The threshold of number of failures.

Integer

camel.health.check.routes.thresholds.mean-processing-time.threshold

The threshold value.

String

camel.health.check.routes.thresholds.min-processing-time.failures

The threshold of number of failures.

Integer

camel.health.check.routes.thresholds.min-processing-time.threshold

The threshold value.

String

camel.health.check.routes.thresholds.redeliveries

Number of redeliveries (internal only).

Long

camel.health.check.service.check-interval

The interval between checks.

String

camel.health.check.service.checks

Configuration of health checks

Map

camel.health.check.service.enabled

Global option to enable/disable extended Camel health checks, default is false.

false

Boolean

camel.health.enabled

Global option to enable/disable camel health bean, default is true.

true

Boolean

camel.language.enabled

Global option to enable/disable language auto-configuration, default is true.

true

Boolean

camel.springboot.allow-use-original-message

Sets whether to allow access to the original message from Camel’s error handler, or from org.apache.camel.spi.UnitOfWork.getOriginalInMessage(). Turning this off can optimize performance, as defensive copy of the original message is not needed. Default is false.

false

Boolean

camel.springboot.auto-startup

Sets whether the object should automatically start when Camel starts. Important: Currently only routes can be disabled, as CamelContext’s are always started. Note: When setting auto startup false on CamelContext then that takes precedence and no routes is started. You would need to start CamelContext explicit using the org.apache.camel.CamelContext.start() method, to start the context, and then you would need to start the routes manually using Camelcontext.getRouteController().startRoute(String). Default is true to always start up.

true

Boolean

camel.springboot.backlog-tracing

Sets whether backlog tracing is enabled or not. Default is false.

false

Boolean

camel.springboot.bean-introspection-extended-statistics

Sets whether bean introspection uses extended statistics. The default is false.

false

Boolean

camel.springboot.bean-introspection-logging-level

Sets the logging level used by bean introspection, logging activity of its usage. The default is TRACE.

LoggingLevel

camel.springboot.case-insensitive-headers

Whether to use case sensitive or insensitive headers. Important: When using case sensitive (this is set to false). Then the map is case sensitive which means headers such as content-type and Content-Type are two different keys which can be a problem for some protocols such as HTTP based, which rely on case insensitive headers. However case sensitive implementations can yield faster performance. Therefore use case sensitive implementation with care. Default is true.

true

Boolean

camel.springboot.consumer-template-cache-size

Consumer template endpoints cache size.

1000

Integer

camel.springboot.duration-max-idle-seconds

To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Spring Boot for a short while.

0

Integer

camel.springboot.duration-max-messages

To specify how many messages to process by Camel before automatic terminating the JVM. You can use this to run Spring Boot for a short while.

0

Integer

camel.springboot.duration-max-seconds

To specify for how long time in seconds to keep running the JVM before automatic terminating the JVM. You can use this to run Spring Boot for a short while.

0

Integer

camel.springboot.endpoint-basic-property-binding

Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities. The default value is false.

false

Boolean

camel.springboot.endpoint-bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. <p/> By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN/ERROR level and ignored. The default value is false.

false

Boolean

camel.springboot.endpoint-lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. The default value is false.

false

Boolean

camel.springboot.endpoint-runtime-statistics-enabled

Sets whether endpoint runtime statistics is enabled (gathers runtime usage of each incoming and outgoing endpoints). The default value is false.

false

Boolean

camel.springboot.file-configurations

Directory to load additional configuration files that contains configuration values that takes precedence over any other configuration. This can be used to refer to files that may have secret configuration that has been mounted on the file system for containers. You must use either file: or classpath: as prefix to load from file system or classpath. Then you can specify a pattern to load from sub directories and a name pattern such as file:/var/app/secret/*.properties

String

camel.springboot.include-non-singletons

Whether to include non-singleton beans (prototypes) when scanning for RouteBuilder instances. By default only singleton beans is included in the context scan.

false

Boolean

camel.springboot.inflight-repository-browse-enabled

Sets whether the inflight repository should allow browsing each inflight exchange. This is by default disabled as there is a very slight performance overhead when enabled.

false

Boolean

camel.springboot.java-routes-exclude-pattern

Used for exclusive filtering component scanning of RouteBuilder classes with @Component annotation. The exclusive filtering takes precedence over inclusive filtering. The pattern is using Ant-path style pattern. Multiple patterns can be specified separated by comma. For example to exclude all classes starting with Bar use: **/Bar* To exclude all routes form a specific package use: com/mycompany/bar/* To exclude all routes form a specific package and its sub-packages use double wildcards: com/mycompany/bar/** And to exclude all routes from two specific packages use: com/mycompany/bar/*,com/mycompany/stuff/*

String

camel.springboot.java-routes-include-pattern

Used for inclusive filtering component scanning of RouteBuilder classes with @Component annotation. The exclusive filtering takes precedence over inclusive filtering. The pattern is using Ant-path style pattern. Multiple patterns can be specified separated by comma. For example to include all classes starting with Foo use: **/Foo* To include all routes form a specific package use: com/mycompany/foo/* To include all routes form a specific package and its sub-packages use double wildcards: com/mycompany/foo/** And to include all routes from two specific packages use: com/mycompany/foo/*,com/mycompany/stuff/*

String

camel.springboot.jmx-enabled

Enable JMX in your Camel application.

true

Boolean

camel.springboot.jmx-management-name-pattern

The naming pattern for creating the CamelContext JMX management name. The default pattern is name

name

String

camel.springboot.jmx-management-statistics-level

Sets the JMX statistics level The level can be set to Extended to gather additional information The default value is Default.

ManagementStatisticsLevel

camel.springboot.lightweight

Experimental: Configure the context to be lightweight. This will trigger some optimizations and memory reduction options. Lightweight context have some limitations. At this moment, dynamic endpoint destinations are not supported.

false

Boolean

camel.springboot.load-type-converters

Whether to load custom type converters by scanning classpath. This is used for backwards compatibility with Camel 2.x. Its recommended to migrate to use fast type converter loading by setting <tt>@Converter(generateLoader = true)</tt> on your custom type converter classes.

true

Boolean

camel.springboot.log-debug-max-chars

Is used to limit the maximum length of the logging Camel message bodies. If the message body is longer than the limit, the log message is clipped. Use -1 to have unlimited length. Use for example 1000 to log at most 1000 characters.

0

Integer

camel.springboot.log-exhausted-message-body

Sets whether to log exhausted message body with message history. Default is false.

false

Boolean

camel.springboot.log-mask

Sets whether log mask is enabled or not. Default is false.

false

Boolean

camel.springboot.main-run-controller

Whether to use the main run controller to ensure the Spring-Boot application keeps running until being stopped or the JVM terminated. You typically only need this if you run Spring-Boot standalone. If you run Spring-Boot with spring-boot-starter-web then the web container keeps the JVM running.

false

Boolean

camel.springboot.mdc-logging-keys-pattern

Sets the pattern used for determine which custom MDC keys to propagate during message routing when the routing engine continues routing asynchronously for the given message. Setting this pattern to * will propagate all custom keys. Or setting the pattern to foo*,bar* will propagate any keys starting with either foo or bar. Notice that a set of standard Camel MDC keys are always propagated which starts with camel. as key name. The match rules are applied in this order (case insensitive): 1. exact match, returns true 2. wildcard match (pattern ends with a * and the name starts with the pattern), returns true 3. regular expression match, returns true 4. otherwise returns false

String

camel.springboot.message-history

Sets whether message history is enabled or not. Default is true.

true

Boolean

camel.springboot.name

Sets the name of the CamelContext.

String

camel.springboot.producer-template-cache-size

Producer template endpoints cache size.

1000

Integer

camel.springboot.route-controller-back-off-delay

Backoff delay in millis when restarting a route that failed to startup.

2000

Long

camel.springboot.route-controller-back-off-max-attempts

Backoff maximum number of attempts to restart a route that failed to startup. When this threshold has been exceeded then the controller will give up attempting to restart the route, and the route will remain as stopped.

0

Long

camel.springboot.route-controller-back-off-max-delay

Backoff maximum delay in millis when restarting a route that failed to startup.

0

Long

camel.springboot.route-controller-back-off-max-elapsed-time

Backoff maximum elapsed time in millis, after which the backoff should be considered exhausted and no more attempts should be made.

0

Long

camel.springboot.route-controller-back-off-multiplier

Backoff multiplier to use for exponential backoff. This is used to extend the delay between restart attempts.

1

Double

camel.springboot.route-controller-exclude-routes

Pattern for filtering routes to be included as supervised. The pattern is matching on route id, and endpoint uri for the route. Multiple patterns can be separated by comma. For example to include all kafka routes, you can say <tt>kafka:*</tt>. And to include routes with specific route ids <tt>myRoute,myOtherRoute</tt>. The pattern supports wildcards and uses the matcher from org.apache.camel.support.PatternHelper#matchPattern.

String

camel.springboot.route-controller-include-routes

Pattern for filtering routes to be excluded as supervised. The pattern is matching on route id, and endpoint uri for the route. Multiple patterns can be separated by comma. For example to exclude all JMS routes, you can say <tt>jms:*</tt>. And to exclude routes with specific route ids <tt>mySpecialRoute,myOtherSpecialRoute</tt>. The pattern supports wildcards and uses the matcher from org.apache.camel.support.PatternHelper#matchPattern.

String

camel.springboot.route-controller-initial-delay

Initial delay in milli seconds before the route controller starts, after CamelContext has been started.

0

Long

camel.springboot.route-controller-route-startup-logging-level

Sets the logging level used for logging route startup activity. By default INFO level is used. You can use this to change the level for example to OFF if this kind of logging is not wanted.

LoggingLevel

camel.springboot.route-controller-supervise-enabled

To enable using supervising route controller which allows Camel to startup and then the controller takes care of starting the routes in a safe manner. This can be used when you want to startup Camel despite a route may otherwise fail fast during startup and cause Camel to fail to startup as well. By delegating the route startup to the supervising route controller then its manages the startup using a background thread. The controller allows to be configured with various settings to attempt to restart failing routes.

false

Boolean

camel.springboot.route-controller-thread-pool-size

The number of threads used by the route controller scheduled thread pool that are used for restarting routes. The pool uses 1 thread by default, but you can increase this to allow the controller to concurrently attempt to restart multiple routes in case more than one route has problems starting.

1

Integer

camel.springboot.route-filter-exclude-pattern

Used for filtering routes routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression. For example to only include routes which starts with foo in their route id’s, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:* Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar* Exclude takes precedence over include.

String

camel.springboot.route-filter-include-pattern

Used for filtering routes routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression. For example to only include routes which starts with foo in their route id’s, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:* Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar* Exclude takes precedence over include.

String

camel.springboot.routes-collector-enabled

Whether the routes collector is enabled or not. When enabled Camel will auto-discover routes (RouteBuilder instances from the registry and also load additional XML routes from the file system. The routes collector is default enabled.

true

Boolean

camel.springboot.shutdown-log-inflight-exchanges-on-timeout

Sets whether to log information about the inflight Exchanges which are still running during a shutdown which didn’t complete without the given timeout. This requires to enable the option inflightRepositoryExchangeEnabled.

true

Boolean

camel.springboot.shutdown-now-on-timeout

Sets whether to force shutdown of all consumers when a timeout occurred and thus not all consumers was shutdown within that period. You should have good reasons to set this option to false as it means that the routes keep running and is halted abruptly when CamelContext has been shutdown.

true

Boolean

camel.springboot.shutdown-routes-in-reverse-order

Sets whether routes should be shutdown in reverse or the same order as they where started.

true

Boolean

camel.springboot.shutdown-suppress-logging-on-timeout

Whether Camel should try to suppress logging during shutdown and timeout was triggered, meaning forced shutdown is happening. And during forced shutdown we want to avoid logging errors/warnings et all in the logs as a side-effect of the forced timeout. Notice the suppress is a best effort as there may still be some logs coming from 3rd party libraries and whatnot, which Camel cannot control. This option is default false.

false

Boolean

camel.springboot.shutdown-timeout

Timeout in seconds to graceful shutdown Camel.

300

Integer

camel.springboot.stream-caching-any-spool-rules

Sets whether if just any of the org.apache.camel.spi.StreamCachingStrategy.SpoolRule rules returns true then shouldSpoolCache(long) returns true, to allow spooling to disk. If this option is false, then all the org.apache.camel.spi.StreamCachingStrategy.SpoolRule must return true. The default value is false which means that all the rules must return true.

false

Boolean

camel.springboot.stream-caching-buffer-size

Sets the stream caching buffer size to use when allocating in-memory buffers used for in-memory stream caches. The default size is 4096.

0

Integer

camel.springboot.stream-caching-enabled

Sets whether stream caching is enabled or not. Default is false.

false

Boolean

camel.springboot.stream-caching-remove-spool-directory-when-stopping

Whether to remove stream caching temporary directory when stopping. This option is default true.

true

Boolean

camel.springboot.stream-caching-spool-cipher

Sets a stream caching cipher name to use when spooling to disk to write with encryption. By default the data is not encrypted.

String

camel.springboot.stream-caching-spool-directory

Sets the stream caching spool (temporary) directory to use for overflow and spooling to disk. If no spool directory has been explicit configured, then a temporary directory is created in the java.io.tmpdir directory.

String

camel.springboot.stream-caching-spool-threshold

Stream caching threshold in bytes when overflow to disk is activated. The default threshold is 128kb. Use -1 to disable overflow to disk.

0

Long

camel.springboot.stream-caching-spool-used-heap-memory-limit

Sets what the upper bounds should be when streamCachingSpoolUsedHeapMemoryThreshold is in use.

String

camel.springboot.stream-caching-spool-used-heap-memory-threshold

Sets a percentage (1-99) of used heap memory threshold to activate stream caching spooling to disk.

0

Integer

camel.springboot.stream-caching-statistics-enabled

Sets whether stream caching statistics is enabled.

false

Boolean

camel.springboot.thread-name-pattern

Sets the thread name pattern used for creating the full thread name. The default pattern is: Camel (camelId) thread #counter - name Where camelId is the name of the CamelContext. and counter is a unique incrementing counter. and name is the regular thread name. You can also use longName which is the long thread name which can includes endpoint parameters etc.

String

camel.springboot.tracing

Sets whether tracing is enabled or not. Default is false.

false

Boolean

camel.springboot.tracing-pattern

Tracing pattern to match which node EIPs to trace. For example to match all To EIP nodes, use to*. The pattern matches by node and route id’s Multiple patterns can be separated by comma.

String

camel.springboot.use-breadcrumb

Set whether breadcrumb is enabled. The default value is false.

false

Boolean

camel.springboot.use-data-type

Whether to enable using data type on Camel messages. Data type are automatic turned on if one ore more routes has been explicit configured with input and output types. Otherwise data type is default off.

false

Boolean

camel.springboot.use-mdc-logging

To turn on MDC logging

false

Boolean

camel.springboot.warn-on-early-shutdown

Whether to log a WARN if Camel on Spring Boot was immediately shutdown after starting which very likely is because there is no JVM thread to keep the application running.

true

Boolean

camel.springboot.xml-rests

Directory to scan for adding additional XML rests. You can turn this off by setting the value to false. Files can be loaded from either classpath or file by prefixing with classpath: or file: Wildcards is supported using a ANT pattern style paths, such as classpath:**/*camel*.xml Multiple directories can be specified and separated by comma, such as: file:/myapp/mycamel/*.xml,file:/myapp/myothercamel/*.xml

classpath:camel-rest/*.xml

String

camel.springboot.xml-routes

Directory to scan for adding additional XML routes. You can turn this off by setting the value to false. Files can be loaded from either classpath or file by prefixing with classpath: or file: Wildcards is supported using a ANT pattern style paths, such as classpath:**/*camel*.xml Multiple directories can be specified and separated by comma, such as: file:/myapp/mycamel/*.xml,file:/myapp/myothercamel/*.xml

classpath:camel/*.xml

String

camel.ssl.cert-alias

An optional certificate alias to use. This is useful when the keystore has multiple certificates.

String

camel.ssl.cipher-suites

The optional explicitly configured cipher suites for this configuration.

CipherSuitesParameters

camel.ssl.cipher-suites-filter

The optional cipher suite filter configuration for this configuration.

FilterParameters

camel.ssl.client-parameters

The optional configuration options to be applied purely to the client side settings of the SSLContext. Settings specified here override any duplicate settings provided at the overall level by this class. These parameters apply to SSLSocketFactory and SSLEngine produced by the SSLContext produced from this class as well as to the SSLContext itself.

SSLContextClientParameters

camel.ssl.config

Global Camel security configuration.

SSLContextParameters

camel.ssl.key-managers

The optional key manager configuration for creating the KeyManager used in constructing an SSLContext.

KeyManagersParameters

camel.ssl.provider

The optional provider identifier for the JSSE implementation to use when constructing an SSLContext.

String

camel.ssl.secure-random

The optional secure random configuration options to use for constructing the SecureRandom used in the creation of an SSLContext.

SecureRandomParameters

camel.ssl.secure-socket-protocol

The optional protocol for the secure sockets created by the SSLContext represented by this instance’s configuration. See Appendix A in the Java Secure Socket Extension Reference Guide for information about standard protocol names.

String

camel.ssl.secure-socket-protocols

The optional explicitly configured secure socket protocol names for this configuration.

SecureSocketProtocolsParameters

camel.ssl.secure-socket-protocols-filter

The option secure socket protocol name filter configuration for this configuration.

FilterParameters

camel.ssl.server-parameters

The optional configuration options to be applied purely to the server side settings of the SSLContext. Settings specified here override any duplicate settings provided at the overall level by this class. These parameters apply to SSLServerSocketFactory and SSLEngine produced by the SSLContext produced from this class as well as to the SSLContext itself.

SSLContextServerParameters

camel.ssl.session-timeout

The optional SSLSessionContext timeout time for javax.net.ssl.SSLSession in seconds.

String

camel.ssl.trust-managers

The optional trust manager configuration for creating the TrustManager used in constructing an SSLContext.

TrustManagersParameters

management.info.camel.enabled

Whether to enable Camel info.

true

Boolean

management.info.camel.verbose

Global option to enable/disable health bean camel version info, default is true.

true

Boolean

Auto-configured Camel context

The most important piece of functionality provided by the Camel auto-configuration is CamelContext instance. Camel auto-configuration creates a SpringCamelContext for you and takes care of the proper initialization and shutdown of that context. The created Camel context is also registered in the Spring application context (under camelContext bean name), so you can access it just as any other Spring bean.

@Configuration
public class MyAppConfig {

  @Autowired
  CamelContext camelContext;

  @Bean
  MyService myService() {
    return new DefaultMyService(camelContext);
  }

}

Auto-detecting Camel routes

Camel auto-configuration collects all the RouteBuilder instances from the Spring context and automatically injects them into the provided CamelContext. That means that creating new Camel route with the Spring Boot starter is as simple as adding the @Component annotated class to your classpath:

@Component
public class MyRouter extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("jms:invoices").to("file:/invoices");
  }

}

Or creating a new route RouteBuilder bean in your @Configuration class:

@Configuration
public class MyRouterConfiguration {

  @Bean
  RoutesBuilder myRouter() {
    return new RouteBuilder() {

      @Override
      public void configure() throws Exception {
        from("jms:invoices").to("file:/invoices");
      }

    };
  }

}

Camel properties

Spring Boot auto-configuration automatically connects to Spring Boot external configuration (like properties placeholders, OS environment variables or system properties) with the Camel properties support. It basically means that any property defined in application.properties file:

route.from = jms:invoices

Or set via system property:

java -Droute.to=jms:processed.invoices -jar mySpringApp.jar

…​can be used as placeholders in Camel route:

@Component
public class MyRouter extends RouteBuilder {

  @Override
  public void configure() throws Exception {
    from("{{route.from}}").to("{{route.to}}");
  }

}

Custom Camel context configuration

If you would like to perform some operations on CamelContext bean created by Camel auto-configuration, register CamelContextConfiguration instance in your Spring context:

@Configuration
public class MyAppConfig {

  @Bean
  CamelContextConfiguration contextConfiguration() {
    return new CamelContextConfiguration() {
      @Override
      void beforeApplicationStart(CamelContext context) {
        // your custom configuration goes here
      }
    };
  }

}

Method beforeApplicationStart` will be called just before the Spring context is started, so the CamelContext instance passed to this callback is fully auto-configured. You can add many instances of CamelContextConfiguration into your Spring context - all of them will be executed.

Disabling JMX

To disable JMX of the auto-configured CamelContext use camel.springboot.jmxEnabled property (JMX is enabled by default). For example you could add the following property to your application.properties file:

camel.springboot.jmx-enabled = false

Auto-configured consumer and producer templates

Camel auto-configuration provides pre-configured ConsumerTemplate and ProducerTemplate instances. You can simply inject them into your Spring-managed beans:

@Component
public class InvoiceProcessor {

  @Autowired
  private ProducerTemplate producerTemplate;

  @Autowired
  private ConsumerTemplate consumerTemplate;

  public void processNextInvoice() {
    Invoice invoice = consumerTemplate.receiveBody("jms:invoices", Invoice.class);
    ...
    producerTemplate.sendBody("netty-http:http://invoicing.com/received/" + invoice.id());
  }

}

By default consumer templates and producer templates come with the endpoint cache sizes set to 1000. You can change those values via the following Spring properties:

camel.springboot.consumer-template-cache-size = 100
camel.springboot.producer-template-cache-size = 200

Auto-configured TypeConverter

Camel auto-configuration registers a TypeConverter instance named typeConverter in the Spring context.

@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public long parseInvoiceValue(Invoice invoice) {
    String invoiceValue = invoice.grossValue();
    return typeConverter.convertTo(Long.class, invoiceValue);
  }

}

Spring type conversion API bridge

Spring comes with the powerful type conversion API. Spring API happens to be very similar to the Camel type converter API. As those APIs are so similar, Camel Spring Boot automatically registers a bridge converter (SpringTypeConverter) that delegates to the Spring conversion API.That means that out-of-the-box Camel will treat Spring Converters like Camel ones. With this approach you can enjoy both Camel and Spring converters accessed via Camel TypeConverter API:

@Component
public class InvoiceProcessor {

  @Autowired
  private TypeConverter typeConverter;

  public UUID parseInvoiceId(Invoice invoice) {
    // Using Spring's StringToUUIDConverter
    UUID id = invoice.typeConverter.convertTo(UUID.class, invoice.getId());
  }

}

Under the hood Camel Spring Boot delegates conversion to the Spring’s ConversionService instances available in the application context. If no ConversionService instance is available, Camel Spring Boot auto-configuration will create one for you.

Disabling type conversions features

If you don’t want Camel Spring Boot to register type-conversions related features (like TypeConverter instance or Spring bridge) set the camel.springboot.type-conversion property to false.

camel.springboot.type-conversion = false

Keeping the application alive

Camel applications having this feature enabled launch a new thread on startup for the sole purpose of keeping the application alive by preventing JVM termination. It means that after you start a Camel application with Spring Boot, your application waits for a Ctrl+C signal and does not exit immediately.

The controller thread can be activated using the camel.springboot.main-run-controller to true.

camel.springboot.main-run-controller = true

Applications using web modules (e.g. importing the org.springframework.boot:spring-boot-web-starter module), usually don’t need to use this feature because the application is kept alive by the presence of other non-daemon threads.

Adding XML routes

By default you can put Camel XML routes in the classpath under the directory camel, which camel-spring-boot will auto detect and include. You can configure the directory name or turn this off using the configuration option

// turn off
camel.springboot.xml-routes = false
// scan in the com/foo/routes classpath
camel.springboot.xml-routes = classpath:com/foo/routes/*.xml

The XML files should be Camel XML routes (not CamelContext) such as

<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="test">
        <from uri="timer://trigger"/>
        <transform>
            <simple>ref:myBean</simple>
        </transform>
        <to uri="log:out"/>
    </route>
</routes>

Adding XML Rest-DSL

By default you can put Camel Rest-DSL XML routes in the classpath under the directory camel-rest, which camel-spring-boot will auto detect and include. You can configure the directory name or turn this off using the configuration option

// turn off
camel.springboot.xml-rests = false
// scan in the com/foo/routes classpath
camel.springboot.xml-rests = classpath:com/foo/rests/*.xml

The Rest-DSL XML files should be Camel XML rests (not CamelContext) such as

<rests xmlns="http://camel.apache.org/schema/spring">
  <rest>
     <post uri="/persons">
        <to uri="direct:postPersons"/>
     </post>
     <get uri="/persons">
        <to uri="direct:getPersons"/>
     </get>
     <get uri="/persons/{personId}">
         <to uri="direct:getPersionId"/>
     </get>
     <put uri="/persons/{personId}">
         <to uri="direct:putPersionId"/>
     </put>
     <delete uri="/persons/{personId}">
         <to uri="direct:deletePersionId"/>
     </delete>
  </rest>
</rests>

Testing the JUnit 4 way

For testing, Maven users will need to add the following dependencies to their pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>${spring-boot.version}</version> <!-- Use the same version as your Spring Boot version -->
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-spring</artifactId>
    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
    <scope>test</scope>
</dependency>

To test a Camel Spring Boot application, annotate your test class(es) with @RunWith(CamelSpringBootRunner.class). This brings Camel’s Spring Test support to your application, so that you can write tests using Spring Boot test conventions.

To get the CamelContext or ProducerTemplate, you can inject them into the class in the normal Spring manner, using @Autowired.

You can also use Camel Spring test annotations to configure tests declaratively. This example uses the @MockEndpoints annotation to auto-mock an endpoint:

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints("direct:end")
public class MyApplicationTest {

    @Autowired
    private ProducerTemplate template;

    @EndpointInject("mock:direct:end")
    MockEndpoint mock;

    @Test
    public void testReceive() throws Exception {
        mock.expectedBodiesReceived("Hello");
        template.sendBody("direct:start", "Hello");
        mock.assertIsSatisfied();
    }

}

Testing the JUnit 5 way

For testing, Maven users will need to add the following dependencies to their pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>${spring-boot.version}</version> <!-- Use the same version as your Spring Boot version -->
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-spring-junit5</artifactId>
    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
    <scope>test</scope>
</dependency>

To test a Camel Spring Boot application, annotate your test class(es) with @CamelSpringBootTest. This brings Camel’s Spring Test support to your application, so that you can write tests using Spring Boot test conventions.

To get the CamelContext or ProducerTemplate, you can inject them into the class in the normal Spring manner, using @Autowired.

You can also use Camel Spring test annotations to configure tests declaratively. This example uses the @MockEndpoints annotation to auto-mock an endpoint:

@CamelSpringBootTest
@SpringBootApplication
@MockEndpoints("direct:end")
public class MyApplicationTest {

    @Autowired
    private ProducerTemplate template;

    @EndpointInject("mock:direct:end")
    private MockEndpoint mock;

    @Test
    public void testReceive() throws Exception {
        mock.expectedBodiesReceived("Hello");
        template.sendBody("direct:start", "Hello");
        mock.assertIsSatisfied();
    }

}