Chapter 2. Migrating to Apache Camel 4
This section provides information that can help you migrate your Apache Camel applications from version 3.20 or higher to 4.0. If you are upgrading from an older Camel 3.x release, such as 3.14, see the individual Upgrade guide to upgrade to the 3.20 release, before upgrading to Apache Camel 4.
- NOTE
The information in the Migration guide is not applicable for IBM Power and IBM Z for this release. This is expected to change in future releases.
2.1. Java versions Copy linkLink copied to clipboard!
Apache Camel 4 supports Java 17. Support for Java 11 is dropped.
2.2. Removed Components Copy linkLink copied to clipboard!
The following components has been removed:
| Component | Alternative component(s) |
|---|---|
| camel-any23 | none |
| camel-atlasmap | none |
| camel-atmos | none |
| camel-caffeine-lrucache | camel-cache, camel-ignite, camel-infinispan |
| camel-cdi | camel-spring-boot, camel-quarkus |
| camel-corda | none |
| camel-directvm | camel-direct |
| camel-dozer | camel-mapstruct |
| camel-elasticsearch-rest | camel-elasticsearch |
| camel-gora | none |
| camel-hbase | none |
| camel-hyperledger-aries | none |
| camel-iota | none |
| camel-ipfs | none |
| camel-jbpm | none |
| camel-jclouds | none |
| camel-johnzon | camel-jackson, camel-fastjson, camel-gson |
| camel-microprofile-metrics | camel-micrometer, camel-opentelemetry |
| camel-milo | none |
| camel-opentracing | camel-micrometer, camel-opentelemetry |
| camel-rabbitmq | spring-rabbitmq-component |
| camel-rest-swagger | camel-openapi-rest |
| camel-restdsl-swagger-plugin | camel-restdsl-openapi-plugin |
| camel-resteasy | camel-cxf, camel-rest |
| camel-solr | none |
| camel-spark | none |
| camel-spring-integration | none |
| camel-swagger-java | camel-openapi-java |
| camel-websocket | camel-vertx-websocket |
| camel-websocket-jsr356 | camel-vertx-websocket |
| camel-vertx-kafka | camel-kafka |
| camel-vm | camel-seda |
| camel-weka | none |
| camel-xstream | camel-jacksonxml |
| camel-zipkin | camel-micrometer, camel-opentelemetry |
2.3. Logging Copy linkLink copied to clipboard!
Camel 4 has upgraded logging facade API slf4j-api from 1.7 to 2.0.
2.4. JUnit 4 Copy linkLink copied to clipboard!
All the camel-test modules that were JUnit 4.x based has been removed. All test modules now use JUnit 5.
2.5. Using stream cache and spooling Copy linkLink copied to clipboard!
Streams are cached in memory. When you are migrating the applications from Red Hat Fuse to Red Hat build of Apache Camel for Spring Boot, spooling must be enabled to prevent the Out Of Memory Errors with big files. For large stream messages, you can set the spoolEnabled=true and then large message (over 128 KB) will be cached in a temporary file instead. Camel itself will handle deleting the temporary file once the cached stream is no longer necessary. In Camel 3 and above the Stream Cache is enabled by default, but the spool is disabled and needs to be enabled. You can use the following property for Camel Spring Boot.
camel.springboot.stream-caching-spool-enabled=true
camel.springboot.stream-caching-spool-enabled=true
2.6. API Changes Copy linkLink copied to clipboard!
Following APIs are deprecated and removed from version 4:
-
The
org.apache.camel.ExchangePatternhas removedInOptionalOut. -
Removed
getEndpointMap()method fromCamelContext. -
Removed
@FallbackConverteras you should use@Converter(fallback = true)instead. -
Removed
uriattribute on@EndpointInject,@Produce, and@Consumeas you should usevalue(default) instead. For example@Produce(uri = "kafka:cheese")should be changed to@Produce("kafka:cheese") -
Removed
labelon@UriEndpointas you should usecategoryinstead. -
Removed all
asyncCallbackmethods onProducerTemplate. UseasyncSendorasyncRequestinstead. -
Removed
org.apache.camel.spi.OnCamelContextStart. Useorg.apache.camel.spi.OnCamelContextStartinginstead. -
Removed
org.apache.camel.spi.OnCamelContextStop. Useorg.apache.camel.spi.OnCamelContextStoppinginstead. -
Decoupled the
org.apache.camel.ExtendedCamelContextfrom theorg.apache.camel.CamelContext. -
Replaced
adapt()fromorg.apache.camel.CamelContextwithgetCamelContextExtension -
Decoupled the
org.apache.camel.ExtendedExchangefrom theorg.apache.camel.Exchange. -
Replaced
adapt()fromorg.apache.camel.ExtendedExchangewithgetExchangeExtension -
Exchange failure handling status has moved from being a property defined as
ExchangePropertyKey.FAILURE_HANDLEDto a member of the ExtendedExchange, accessible via `isFailureHandled()`method. -
Removed
DiscardandDiscardOldestfromorg.apache.camel.util.concurrent.ThreadPoolRejectedPolicy. -
Removed
org.apache.camel.builder.SimpleBuilder. Was mostly used internally in Camel with the Java DSL in some situations. -
Moved
org.apache.camel.support.IntrospectionSupporttocamel-core-enginefor internal use only. End users should useorg.apache.camel.spi.BeanInspectioninstead. -
Removed
archetypeCatalogAsXmlmethod fromorg.apache.camel.catalog.CamelCatalog. -
The
org.apache.camel.health.HealthCheckmethodisLivenessis now defaultfalseinstead oftrue. -
Added
positionmethod toorg.apache.camel.StreamCache. -
The method
configurefrom the interfaceorg.apache.camel.main.Listenerwas removed -
The
org.apache.camel.support.EventNotifierSupportabstract class now implementsCamelContextAware. -
The type for
dumpRoutesonCamelContexthas changed frombooleantoStringto allow specifying either xml or yaml.
The org.apache.camel.support.PluginHelper gives easy access to various extensions and context plugins, that was available previously in Camel v3 directly from CamelContext.
2.7. EIP Changes Copy linkLink copied to clipboard!
-
Removed
langattribute for the<description>on every EIPs. -
The
InOnlyandInOutEIPs has been removed. Instead, useSetExchangePatternorTowhere you can specify exchange pattern to use.
2.7.1. Poll Enrich EIP Copy linkLink copied to clipboard!
The polled endpoint URI is now stored as property on the Exchange (with key CamelToEndpoint) like all other EIPs. Before the URI was stored as a message header.
2.7.2. CircuitBreaker EIP Copy linkLink copied to clipboard!
The following options in camel-resilience4j was mistakenly not defined as attributes:
| Option |
| bulkheadEnabled |
| bulkheadMaxConcurrentCalls |
| bulkheadMaxWaitDuration |
| timeoutEnabled |
| timeoutExecutorService |
| timeoutDuration |
| timeoutCancelRunningFuture |
These options were not exposed in YAML DSL, and in XML DSL you need to migrate from:
To use following attributes instead:
<circuitBreaker>
<resilience4jConfiguration timeoutEnabled="true" timeoutDuration="2000"/>
...
</circuitBreaker>
<circuitBreaker>
<resilience4jConfiguration timeoutEnabled="true" timeoutDuration="2000"/>
...
</circuitBreaker>
2.8. XML DSL Copy linkLink copied to clipboard!
The <description> to set a description on a route or node, has been changed from an element to an attribute.
Example
Changed from
<route id="myRoute"> <description>Something that this route do</description> <from uri="kafka:cheese"/> ... </route>
<route id="myRoute">
<description>Something that this route do</description>
<from uri="kafka:cheese"/>
...
</route>
To
<route id="myRoute" description="Something that this route do"> <from uri="kafka:cheese"/> ... </route>
<route id="myRoute" description="Something that this route do">
<from uri="kafka:cheese"/>
...
</route>
We recommend that you use xml-io-dsl parser for Camel XML DSL. It works with all Camel runtimes. To use the xml-io-dsl parser, add the following dependency to your project’s pom.xml.
<dependency>
<groupId>org.apache.camel.springbboot</groupId>
<artifactId>camel-xml-io-dsl-starter</artifactId>
<version>{CamelSBProjectVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.springbboot</groupId>
<artifactId>camel-xml-io-dsl-starter</artifactId>
<version>{CamelSBProjectVersion}</version>
</dependency>
The version can be omitted if you are using the BOM for your application.
For more information about XML IO DSL, refer XML IO DSL.
2.9. Type Converter Copy linkLink copied to clipboard!
The String java.io.File converter has been removed.
2.10. Tracing Copy linkLink copied to clipboard!
The Tracer and Backlog Tracer no longer includes internal tracing events from routes that was created by Rest DSL or route templates or Kamelets. You can turn this on, by setting traceTemplates=true in the tracer.
The Backlog Tracer has been enhanced and fixed to trace message headers (also streaming types). This means that previously headers of type InputStream was not traced before, but is now included. This could mean that the header stream is positioned at end, and logging the header afterward, may appear as the header value is empty.
2.11. UseOriginalMessage / UseOriginalBody Copy linkLink copied to clipboard!
When useOriginalMessage or useOriginalBody is enabled in OnException, OnCompletion or error handlers, then the original message body is defensively copied and if possible converted to StreamCache to ensure the body can be re-read when accessed. Previously the original body was not converted to StreamCache which could lead to the body not able to be read or the stream has been closed.
2.12. Camel Health Copy linkLink copied to clipboard!
Health checks are now by default only readiness checks out of the box. Camel provides the CamelContextCheck as both readiness and liveness checks, so there is at least one of each out of the box. Only consumer based health-checks is enabled by default.
2.12.1. Producer Health Checks Copy linkLink copied to clipboard!
The option camel.health.components-enabled has been renamed to camel.health.producers-enabled.
Some components (in particular AWS) provides also health checks for producers; in Camel 3.x these health checks did not work properly and has been disabled in the source. To continue this behaviour in Camel 4, the producer based health checks are disabled.
Notice that camel-kafka comes with producer based health-check that worked in Camel 3, and therefore this change in Camel 4, means that this health-check is disabled.
You MUST enable producer health-checks globally, such as in application.properties:
camel.health.producers-enabled = true
camel.health.producers-enabled = true
2.13. JMX Copy linkLink copied to clipboard!
Camel now also include MBeans for doCatch and doFinally in the tree of processor MBeans.
The ManagedChoiceMBean have renamed choiceStatistics to extendedInformation. The ManagedFailoverLoadBalancerMBean have renamed exceptionStatistics to extendedInformation.
The CamelContextMBean and CamelRouteMBean has removed method dumpRouteAsXml(boolean resolvePlaceholders, boolean resolveDelegateEndpoints).
2.14. YAML DSL Copy linkLink copied to clipboard!
The backwards compatible mode Camel 3.14 or older, which allowed to have steps as child to route has been removed.
The old syntax:
- route:
from:
uri: "direct:info"
steps:
- log: "message"
- route:
from:
uri: "direct:info"
steps:
- log: "message"
should be changed to:
- route:
from:
uri: "direct:info"
steps:
- log: "message"
- route:
from:
uri: "direct:info"
steps:
- log: "message"
2.15. Backlog Tracing Copy linkLink copied to clipboard!
The option backlogTracing=true is now automatically enabled to start the tracer on startup. In the previous versions the tracer was only made available, and had to be manually enabled afterwards. The old behavior can be archived by setting backlogTracingStandby=true.
Move the following class from org.apache.camel.api.management.mbean.BacklogTracerEventMessage in camel-management-api JAR to org.apache.camel.spi.BacklogTracerEventMessage in camel-api JAR.
The org.apache.camel.impl.debugger.DefaultBacklogTracerEventMessage has been refactored into an interface org.apache.camel.spi.BacklogTracerEventMessage with some additional details about traced messages. For example Camel now captures a first and last trace that contains the input and outgoing (if InOut) messages.
2.16. XML serialization Copy linkLink copied to clipboard!
The default xml serialization using ModelToXMLDumper has been improved and now uses a generated xml serializer located in the camel-xml-io module instead of the JAXB based one from camel-jaxb.
2.17. OpenAPI Maven Plugin Copy linkLink copied to clipboard!
The camel-restdsl-openapi-plugin Maven plugin now uses platform-http as the default rest component in the generated Rest DSL code. Previously the default was servlet. However, platform-http is a better default that works out of the box with Spring Boot and Quarkus.
2.18. Component changes Copy linkLink copied to clipboard!
2.18.1. Category Copy linkLink copied to clipboard!
The number of enums for org.apache.camel.Category has been reduced from 83 to 37, which means custom components that are using removed values need to choose one of the remainder values. We have done this to consolidate the number of categories of all components in the Camel community.
2.18.2. camel-openapi-rest-dsl-generator Copy linkLink copied to clipboard!
This dsl-generator has updated the underlying model classes (apicurio-data-models) from 1.1.27 to 2.0.3.
2.18.3. camel-atom Copy linkLink copied to clipboard!
The camel-atom component has changed the 3rd party atom client from Apache Abdera to RSSReader. This means the feed object is changed from org.apache.abdera.model.Feed to com.apptasticsoftware.rssreader.Item.
2.18.4. camel-azure-cosmosdb Copy linkLink copied to clipboard!
The itemPartitionKey has been updated. It’s now a String a not a PartitionKey anymore. More details in CAMEL-19222.
2.18.5. camel-bean Copy linkLink copied to clipboard!
When using the method option to refer to a specific method, and using parameter types and values, such as: "bean:myBean?method=foo(com.foo.MyOrder, true)" then any class types must now be using .class syntax, i.e. com.foo.MyOrder should now be com.foo.MyOrder.class.
Example
"bean:myBean?method=foo(com.foo.MyOrder.class, true)"
"bean:myBean?method=foo(com.foo.MyOrder.class, true)"
This also applies to Java types such as String, int.
"bean:myBean?method=bar(String.class, int.class)"
"bean:myBean?method=bar(String.class, int.class)"
2.18.6. camel-box Copy linkLink copied to clipboard!
Upgraded from Box Java SDK v2 to v4, which have some method signature changes. The method to get a file thumbnail is no longer available.
2.18.7. camel-caffeine Copy linkLink copied to clipboard!
The keyType parameter has been removed. The Key for the cache will now be only String type. More information in CAMEL-18877.
2.18.8. camel-fhir Copy linkLink copied to clipboard!
The underlying hapi-fhir library has been upgraded from 4.2.0 to 6.2.4. Only the Delete API method has changed and now returns ca.uhn.fhir.rest.api.MethodOutcome instead of org.hl7.fhir.instance.model.api.IBaseOperationOutcome. See hapi-fhir for a more detailed list of underlying changes (only the hapi-fhir client is used in Camel).
2.18.9. camel-google Copy linkLink copied to clipboard!
The API based components camel-google-drive, camel-google-calendar, camel-google-sheets and camel-google-mail has been upgraded from Google Java SDK v1 to v2 and to latest API revisions. The camel-google-drive and camel-google-sheets have some API methods changes, but the others are identical as before.
2.18.10. camel-http Copy linkLink copied to clipboard!
The component has been upgraded to use Apache HttpComponents v5 which has an impact on how the underlying client is configured. There are 4 different timeouts (connectionRequestTimeout, connectTimeout, soTimeout and responseTimeout) instead of initially 3 (connectionRequestTimeout, connectTimeout and socketTimeout) and the default value of some of them has changed so please refer to the documentation for more details.
Please note that the socketTimeout has been removed from the possible configuration parameters of HttpClient, use responseTimeout instead.
Finally, the option soTimeout along with any parameters included into SocketConfig, need to be prefixed by httpConnection., the rest of the parameters including those defined into HttpClientBuilder and RequestConfig still need to be prefixed by httpClient. like before.
2.18.11. camel-http-common Copy linkLink copied to clipboard!
The API in org.apache.camel.http.common.HttpBinding has changed slightly to be more reusable. The parseBody method now takes in HttpServletRequest as input parameter. And all HttpMessage has been changed to generic Message types.
2.18.12. camel-kubernetes Copy linkLink copied to clipboard!
The io.fabric8:kubernetes-client library has been upgraded and some deprecated API usage has been removed. Operations previously prefixed with replace are now prefixed with update.
For example replaceConfigMap is now updateConfigMap, replacePod is now updatePod etc. The corresponding constants in class KubernetesOperations are also renamed. REPLACE_CONFIGMAP_OPERATION is now UPDATE_CONFIGMAP_OPERATION, REPLACE_POD_OPERATION is now UPDATE_POD_OPERATION etc.
2.18.13. camel-main Copy linkLink copied to clipboard!
The following constants has been moved from BaseMainSupport / Main to MainConstants:
| Old Name | New Name |
|---|---|
| Main.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION | MainConstants.DEFAULT_PROPERTY_PLACEHOLDER_LOCATION |
| Main.INITIAL_PROPERTIES_LOCATION | MainConstants.INITIAL_PROPERTIES_LOCATION |
| Main.OVERRIDE_PROPERTIES_LOCATION | MainConstants.OVERRIDE_PROPERTIES_LOCATION |
| Main.PROPERTY_PLACEHOLDER_LOCATION | MainConstants.PROPERTY_PLACEHOLDER_LOCATION |
2.18.14. camel-micrometer Copy linkLink copied to clipboard!
The metrics has been renamed to follow Micrometer naming convention .
| Old Name | New Name |
| CamelExchangeEventNotifier | camel.exchange.event.notifier |
| CamelExchangesFailed | camel.exchanges.failed |
| CamelExchangesFailuresHandled | camel.exchanges.failures.handled |
| CamelExchangesInflight | camel.exchanges.external.redeliveries |
| CamelExchangesSucceeded | camel.exchanges.succeeded |
| CamelExchangesTotal | camel.exchanges.total |
| CamelMessageHistory | camel.message.history |
| CamelRoutePolicy | camel.route.policy |
| CamelRoutePolicyLongTask | camel.route.policy.long.task |
| CamelRoutesAdded | camel.routes.added |
| CamelRoutesRunning | camel.routes.running |
2.18.15. camel-jbang Copy linkLink copied to clipboard!
The command camel dependencies has been renamed to camel dependency.
In Camel CLI the -dir parameter for init and run goal has been renamed to require 2 dashes --dir like all the other options.
The camel stop command will now by default stop all running integrations (the option --all has been removed).
The Placeholders substitutes is changed to use #name instead of $name syntax.
2.18.16. camel-openapi-java Copy linkLink copied to clipboard!
The camel-openapi-java component has been changed to use io.swagger.v3 libraries instead of io.apicurio.datamodels. As a result, the return type of the public method org.apache.camel.openapi.RestOpenApiReader.read() is now io.swagger.v3.oas.models.OpenAPI instead of io.apicurio.datamodels.openapi.models.OasDocument. When an OpenAPI 2.0 (swagger) specification is parsed, it is automatically upgraded to OpenAPI 3.0.x by the swagger parser. This version also supports OpenAPI 3.1.x specifications. The related spring-boot starter components have been modified to use the new return type.
2.18.17. camel-salesforce Copy linkLink copied to clipboard!
Property names of blob fields on generated DTOs no longer have 'Url' affixed. For example, the ContentVersionUrl property is now ContentVersion.
2.18.18. camel-slack Copy linkLink copied to clipboard!
The default delay (on slack consumer) is changed from 0.5s to 10s to avoid being rate limited to often by Slack.
2.18.19. camel-spring-rabbitmq Copy linkLink copied to clipboard!
The option replyTimeout in camel-spring-rabbitmq has been fixed and the default value from 5 to 30 seconds (this is the default used by Spring).
2.19. Camel Spring Boot Copy linkLink copied to clipboard!
The camel-spring-boot dependency no longer includes camel-spring-xml. To use legacy Spring XML files <beans> with Camel on Spring Boot, then include the camel-spring-boot-xml-starter dependency.
2.19.1. Using restConfiguration in a Spring Bean XML Copy linkLink copied to clipboard!
When declaring a restConfiguration in a Spring Beans XML file, for example:
<camelContext id="SampleCamel" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration port="8080" bindingMode="off" scheme="http"
contextPath="myapi" apiContextPath="myapi/swagger">
</restConfiguration>
<camelContext id="SampleCamel" xmlns="http://camel.apache.org/schema/spring">
<restConfiguration port="8080" bindingMode="off" scheme="http"
contextPath="myapi" apiContextPath="myapi/swagger">
</restConfiguration>
The Camel Spring Boot application does not start due to a circular references error. The RestConfigurationDefinitionAutoConfiguration property is used when you use the Spring properties to configure the REST component. When you define the REST configuration in the XML file, the RestConfigurationDefinitionAutoConfiguration property is not needed. You can disable this property as follows:
SampleCamelApplication.java
@SpringBootApplication(exclude = RestConfigurationDefinitionAutoConfiguration.class)
// load the spring xml file from classpath
@ImportResource("classpath:my-camel.xml")
public class SampleCamelApplication {
@SpringBootApplication(exclude = RestConfigurationDefinitionAutoConfiguration.class)
// load the spring xml file from classpath
@ImportResource("classpath:my-camel.xml")
public class SampleCamelApplication {
2.19.2. Graceful Shutdown Copy linkLink copied to clipboard!
Camel now shutdowns a bit later during Spring Boot shutdown. This allows Spring Boot graceful shutdown to complete first (stopping Spring Boot HTTP server gracefully), and then afterward Camel is doing its own Graceful Shutdown.
Technically camel-spring has changed getPhase() from returning Integer.MAX_VALUE to Integer.MAX_VALUE - 2049. This gives room for Spring Boot services to shut down first.
2.19.3. camel-micrometer-starter Copy linkLink copied to clipboard!
The uri tags are now static instead of dynamic (by default), as potential too many tags generated due to URI with dynamic values. This can be enabled again by setting camel.metrics.uriTagDynamic=true.
2.19.4. camel-platform-http-starter Copy linkLink copied to clipboard!
The platform-http-starter has been changed from using camel-servlet to use Spring HTTP server directly. Therefore, all the HTTP endpoints are no longer prefixed with the servlet context-path (default is camel).
For example:
from("platform-http:myservice")
.to("...")
from("platform-http:myservice")
.to("...")
Then calling myservice would before require to include the context-path, such as http://localhost:8080/camel/myservice. Now the context-path is not in use, and the endpoint can be called with http://localhost:8080/myservice.
The platform-http-starter can also be used with Rest DSL.
If the route or consumer is suspended then http status 503 is now returned instead of 404.
2.19.5. camel-twitter Copy linkLink copied to clipboard!
The component was updated to use Twitter4j version 4.1.2, which has moved the packages used by a few of its classes. If accessing certain twitter-related data, such as the Twit status, you need to update the packages used from twitter4j.Status to twitter4j.v1.Status.