Camel 2.x 到 3.0 迁移指南
Apache Camel 2.x 到 3.0 迁移指南
本文档旨在帮助你将 Apache Camel 应用从 2.x 版本迁移到 3.0。
| 如果你是从 Camel 3.x 升级到 3.y,请使用 Camel 3.x 升级指南。 |
|---|
Java 版本
Camel 3 支持 Java 11。对于 Camel 3 的早期版本,对 Java 8 的支持仅为尽力而为。然而,在 3.x 生命周期的某个阶段,我们将停止对 Java 8 的支持。
在 Java 11 中,JAXB 模块已从 JDK 中移除,因此你需要将它们添加为 Maven 依赖(如果你使用 JAXB,例如在使用 XML DSL 或 camel-jaxb 组件时):
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>camel-core 的模块化
最大的变化之一是 camel-core 的模块化。在 Camel 2.x 中,camel-core 是一个 JAR 文件,现在它被拆分成了许多 JAR,如下所示:
- camel-api
- camel-base
- camel-caffeine-lrucache
- camel-cloud
- camel-core
- camel-jaxp
- camel-main
- camel-management-api
- camel-management
- camel-support
- camel-util
- camel-util-json
Apache Camel 的 Maven 用户可以继续使用 camel-core 依赖,该依赖通过传递依赖引入了它的所有模块(camel-main 除外),因此无需进行迁移。不过,如果希望精简 classpath 上的类数量,则可以只针对所需的模块使用细粒度的 Maven 依赖。有关如何操作,可以参见示例。
我们还将许多核心组件进行了模块化,把它们从 camel-core 中移出,成为独立的组件:
- camel-attachments
- camel-bean
- camel-browse
- camel-controlbus
- camel-dataformat
- camel-dataset
- camel-direct
- camel-directvm
- camel-file
- camel-language
- camel-log
- camel-mock
- camel-ref
- camel-rest
- camel-saga
- camel-scheduler
- camel-seda
- camel-stub
- camel-timer
- camel-validator
- camel-vm
- camel-xpath
- camel-xslt
- camel-xslt-saxon
- camel-zip-deflater
Spring Boot starter 的 Maven 坐标变更
Spring Boot starter 的 Maven groupId 变更为:org.apache.camel.springboot。
不再是:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-component-starter</artifactId>
</dependency>使用:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-component-starter</artifactId>
</dependency>一个应用不支持多个 CamelContext
对多个 CamelContext 的支持已被移除,每个部署只支持 1 个 CamelContext。实际上,后者本来就不被推荐,而且也并未 100% 实现,例如 camel-cdi 中就是如此。对于 Camel 3,推荐并支持每个部署只使用 1 个 CamelContext。
因此,@EndpointInject、@Produce、@Consume 等各种 Camel 注解上的 context 属性已被移除。
迁移自定义组件
你应该依赖 camel-support,而不是直接依赖 camel-core。
org.apache.camel.impl 中那些旨在支持 Camel 开发者构建自定义组件的类,已从 camel-core 移出,进入 camel-support 的 org.apache.camel.support 包中。例如 DefaultComponent、DefaultEndpoint 等类已被移动,因此需要进行迁移。
迁移自定义语言
LanguageAnnotation 注解类已从 org.apache.camel.language 包移动到 org.apache.camel.support.language 包。
迁移 DefaultShutdownStrategy
DefaultShutdownStrategy 类已从 org.apache.camel.impl 包移动到 org.apache.camel.impl.engine 包。
已弃用的 API 和组件
Camel 2.x 中所有已弃用的 API 和组件在 Camel 3 中已被移除。
迁移 Camel 应用
Main 类
Camel 的 Main 类已从 camel-core 移出,进入 camel-main,因此如果你使用 Main,应该将该模块添加为依赖。
properties 组件
properties 组件已移除对自定义前缀和后缀标记(token)的配置,因为如果使用它们,可能会与 simple 语言等产生冲突问题。默认的标记现在已硬编码并始终生效。
properties 组件移除了一些高级选项:propertyPrefix、propertySuffix 和 fallbackToUnaugmented;这些选项本来也从未真正可供最终用户使用。propertiesResolver 选项也已被移除,你应该改用 PropertiesSource。
属性组件(properties component)现在会优先使用操作系统环境变量。这意味着你可以设置一个操作系统环境变量,它将覆盖在属性文件、JVM 系统属性等中设置的任何属性值。你可以通过属性组件上的 environmentVariableMode 选项进行配置。
properties 组件不再支持作为端点使用,例如 properties:myKey。属性组件现在只是一个属性占位符服务。因此,你不能再通过 camelContext.getComponent("properties") 来获取属性组件。相反,你可以使用 camelContext.getPropertiesComponent(),它同样返回属性组件的接口 org.apache.camel.spi.PropertiesComponent。其实现类仍名为 org.apache.camel.component.properties.PropertiesComponent,但很少会直接使用它,建议优先使用该接口。
已移除的组件
我们移除了 Camel 2.x 中所有已弃用的组件,包括旧的 camel-http、camel-hdfs、camel-mina、camel-mongodb、camel-netty、camel-netty-http、camel-quartz、camel-restlet 和 camel-rx 组件。
我们移除了在 JDK 8 上无法正常工作的 camel-jibx 组件。
我们移除了在 JDK 9 及更高版本上无法正常工作的 camel-boon 数据格式(dataformat)。
我们移除了 camel-linkedin 组件,并且没有替代方案。
我们移除了 camel-rmi 组件,并且没有替代方案。
camel-zookeeper 的路由策略功能已被移除,请改用 ZooKeeperClusterService 或 camel-zookeeper-master 组件。
camel-jetty 组件不再支持生产者(例如 to 端点),该功能已被移除,请改用 camel-http 组件。
twitter-streaming 组件已被移除,因为它依赖于已弃用的 Twitter Streaming API,已不再可用。
已重命名的组件
test 组件已重命名为 dataset-test,并从 camel-core 移出到 camel-dataset JAR 中。
http4 组件已重命名为 http,其对应的组件包也从 org.apache.camel.component.http4 改为 org.apache.camel.component.http。现在支持的协议 scheme 仅为 http 和 https。
hdfs2 组件已重命名为 hdfs,其对应的组件包也从 org.apache.camel.component.hdfs2 改为 org.apache.camel.component.hdfs。现在支持的协议 scheme 为 hdfs。
mina2 组件已重命名为 mina,其对应的组件包也从 org.apache.camel.component.mina2 改为 org.apache.camel.component.mina。现在支持的协议 scheme 为 mina。
mongodb3 组件已更名为 mongodb,其对应的组件包也从 org.apache.camel.component.mongodb3 更改为 org.apache.camel.component.mongodb。现在支持的 scheme 为 mongodb。
netty4-http 组件已更名为 netty-http,其对应的组件包也从 org.apache.camel.component.netty4.http 更改为 org.apache.camel.component.netty.http。现在支持的 scheme 为 netty-http。
netty4 组件已更名为 netty,其对应的组件包也从 org.apache.camel.component.netty4 更改为 org.apache.camel.component.netty。现在支持的 scheme 为 netty。
quartz2 组件已更名为 quartz,其对应的组件包也从 org.apache.camel.component.quartz2 更改为 org.apache.camel.component.quartz。现在支持的 scheme 为 quartz。
rxjava2 组件已更名为 rxjava,其对应的组件包也从 org.apache.camel.component.rxjava2 更改为 org.apache.camel.component.rxjava。
我们还将 camel-jetty9 更名为 camel-jetty。现在支持的 scheme 为 jetty。
Hystrix EIP
Hystrix EIP 已被泛化为熔断器(circuit breaker),以便能够接入其他实现。
在 Java DSL 中,你需要从 .hystrix() 迁移到 .circuitBreaker()。在 XML DSL 中,<hystrix> 应改为 <circuitBreaker>。
使用带 consumer. 前缀的端点选项
带有 consumer. 前缀的端点选项(例如 consumer.delay=5000)已不再支持(在最新的 Camel 2.x 中已弃用),你应该直接使用不带 consumer. 前缀的选项,例如 delay=5000。
将处理器作为端点调用
在路由中将处理器作为端点调用,例如:
仅限 Java:将处理器作为端点调用(已不再支持)
from("jms:cheese")
.to("myProcessor");不再受支持。可以改为使用 bean 组件来调用处理器,或者使用 process:
仅限 Java:使用 bean 组件调用处理器
from("jms:cheese")
.to("bean:myProcessor");或者
纯 Java 方式:使用 process 调用处理器
from("jms:cheese")
.process("myProcessor");追踪
新的追踪器已实现,旧的追踪器已被移除。新的追踪器使用硬编码的 org.apache.camel.Tracing logger 名称来记录消息。输出格式也已更新,以使其更清晰。追踪器可以进行自定义。
在 JMX 中,BacklogTracer 不再默认启用,你需要通过在 CamelContext 上设置 backlogTracing=true 来启用它。积压追踪器(backlog tracer)与追踪器(tracer)并不相同。前者用于捕获追踪消息的积压数据,你可以通过 JMX 进行轮询(第三方工具需要此功能),而追踪器则写入日志。两者默认都未启用,必须显式启用才会生效。
XML DSL 中的 <setHeader> 和 <setProperty>
我们已将 XML DSL 中 <setHeader> 和 <setProperty> 这两个 EIP 的 headerName 和 propertyName 属性重命名为统一的 name。
因此请按以下方式进行迁移
<setHeader headerName="foo"><simple>Hello ${body}</simple></setHeader>至
<setHeader name="foo"><simple>Hello ${body}</simple></setHeader><setProperty> 同理。
EIP in XML DSL
aggregate EIP 已将用于设置关联大小/超时的表达式(而非属性)重命名,以避免名称冲突,因此请进行如下迁移:
<completionSize>
<header>mySize</header>
</completionSize>至
<completionSizeExpression>
<header>mySize</header>
</completionSizeExpression><completionTimeout> 也同样如此。
XML 中的 <threads> <delay> <sample> <throttle> EIP
这些 EIP 已经过改进,不再使用子元素来进行路由,而是像其他 EIP 一样折叠为单个元素。
因此,在此之前你可能会写成:
<route>
<from uri="jms:cheese"/>
<to uri="log:before"/>
<threads poolSize="2">
<to uri="bean:foo"/>
<to uri="bean:bar"/>
</threads>
<to uri="log:after"/>
</route>而现在你会这样做:
<route>
<from uri="jms:cheese"/>
<to uri="log:before"/>
<threads poolSize="2"/>
<to uri="bean:foo"/>
<to uri="bean:bar"/>
<to uri="log:after"/>
</route>其他 EIP <delay>、<sample> 和 <throttle> 也是如此。
camel-cdi
对多个 CamelContext 的支持已被移除,因此 @ContextName 也被移除了。请改用标准的 CDI 注解,如 @Named 和 @ApplicationScoped。
javax.script
camel-script 组件已被移除,并且不再支持 javax.script;该技术在 JDK 中也已废弃,并将从 Java 11 起被移除。
Message 上的附件 API
附件 API(javax.activation)已从 org.apache.camel.message 中移出,成为来自 camel-attachments JAR 的扩展 org.apache.camel.attachment.AttachmentMessage。
要使用该 API,可以通过 Exchange 上的 getMessage 方法获取它:
AttachmentMessage am = exchange.getMessage(AttachmentMessage.class);
am.addAttachment("myAtt", new DataHandler(...));Message 上的 Fault API
Fault API 已从 org.apache.camel.Message 中移除,因为它仅用于 SOAP-WS 故障消息。用于 SOAP-WS 的 camel-cxf 和 camel-spring-ws 组件已被修改,以支持其各自组件产生的故障消息。选项 handleFault 也已被移除,现在你需要将其作为 camel-cxf 或 camel-spring-ws 的端点选项或组件选项来启用。
Exchange 上的 getOut
Exchange 上的 hasOut 和 getOut 方法已废弃,建议改用 getMessage。(附带说明:camel-core 在少数地方仍在使用这些方法以保持向后兼容,并依赖这一逻辑,因为 Camel 最初是受 JBI 和 SOAP-WS 规范启发,围绕 IN 和 OUT 消息的概念设计的。)
Simple 语言和 Mock 组件中移除了 OUT 消息
Simple 语言已移除 OUT 消息的概念,例如 ${out.body}。同样,mock 组件也从其断言 API 中移除了 OUT 消息,例如
mock.message(0).outBody()...此外,用于 bean 参数绑定的 @OutHeaders 注解已被移除,请改用 @Headers。
Mock 组件
mock 组件已从 camel-core 中移出,作为这项工作的一部分,我们不得不删除其断言子句构建器上一些极少使用的方法。
ActiveMQ
如果你使用的是 activemq-camel 组件,则应迁移到使用 camel-activemq 组件,其中组件类名已从 org.apache.activemq.camel.component.ActiveMQComponent 变更为 org.apache.camel.component.activemq.ActiveMQComponent。
AWS
camel-aws 组件已被拆分为多个组件:
- camel-aws-cw
- camel-aws-ddb(同时包含 ddb 和 ddbstreams 组件)
- camel-aws-ec2
- camel-aws-iam
- camel-aws-kinesis(同时包含 kinesis 和 kinesis-firehose 组件)
- camel-aws-kms
- camel-aws-lambda
- camel-aws-mq
- camel-aws-s3
- camel-aws-sdb
- camel-aws-ses
- camel-aws-sns
- camel-aws-sqs
- camel-aws-swf
因此你需要显式添加这些组件的依赖。从 OSGi 的角度来看,仍然存在一个 camel-aws Karaf feature,它包含了所有组件的 feature。
FHIR
camel-fhir 组件已将其 hapi-fhir 依赖升级到 4.1.0;在 hapi-fhir 的 Karaf feature 被修复并发布之前,Karaf 支持已被移除。默认的 FHIR 版本已改为 R4。因此,如果需要使用 DSTU3,必须显式进行设置。
Kafka
camel-kafka 组件已移除 bridgeEndpoint 和 circularTopicDetection 选项,因为该组件的行为与 Camel 2.x 上的桥接方式一致,这些选项已不再需要。换句话说,camel-kafka 将把消息发送到端点 URI 中指定的 topic。若要覆盖此行为,请使用 KafkaConstants.OVERRIDE_TOPIC 请求头指定新的 topic。更多详情请参阅 camel-kafka 组件文档。
Telegram
camel-telegram 组件已将授权令牌从 URI 路径改为查询参数,例如迁移
telegram:bots/myTokenHere到
telegram:bots?authorizationToken=myTokenHereJMX
如果你以独立方式运行 Camel,仅将 camel-core 作为依赖项,并且希望开箱即可启用 JMX,则需要将 camel-management 添加为依赖项。
要使用 ManagedCamelContext,现在需要按如下方式从 CamelContext 获取该扩展:
ManagedCamelContext managed = camelContext.getExtension(ManagedCamelContext.class);XSLT
XSLT 组件已从 camel-core 移出到 camel-xslt 和 camel-xslt-saxon 中。该组件被拆分,因此 camel-xslt 用于使用 JDK XSLT 引擎(Xalan),而 camel-xslt-saxon 用于使用 Saxon。这意味着在 Camel 端点 URI 中应使用 xslt 和 xslt-saxon 作为组件名称。如果使用 XSLT 聚合策略,Saxon 支持请使用 org.apache.camel.component.xslt.saxon.XsltSaxonAggregationStrategy;如果使用 xslt builder,Saxon 支持请使用 org.apache.camel.component.xslt.saxon.XsltSaxonBuilder。同时请注意,allowStax 也仅在 camel-xslt-saxon 中受支持,因为 JDK XSLT 不支持该功能。
camel-sql
JdbcAggregationRepository 的乐观锁功能已修复,可在分布式环境和各类数据库中正常工作。新增了一个必需的 version 列,必须将其添加到仓库表中:
CREATE TABLE aggregation (
id varchar(255) NOT NULL,
exchange blob NOT NULL,
version BIGINT NOT NULL,
constraint aggregation_pk PRIMARY KEY (id)
);
CREATE TABLE aggregation_completed (
id varchar(255) NOT NULL,
exchange blob NOT NULL,
version BIGINT NOT NULL,
constraint aggregation_completed_pk PRIMARY KEY (id)
);在 CamelContext 上配置全局选项
在 Camel 2.x 中,我们已经弃用了 CamelContext 上的 getProperties,转而使用 getGlobalOptions,因此你应该迁移为:
context.getGlobalOptions().put("CamelJacksonEnableTypeConverter", "true");
context.getGlobalOptions().put("CamelJacksonTypeConverterToPojo", "true");以及在 XML 中:
<globalOptions>
<globalOption key="CamelJacksonEnableTypeConverter" value="true"/>
<globalOption key="CamelJacksonTypeConverterToPojo" value="true"/>
</globalOptions>Main 类
来自 camel-core、camel-spring 和 camel-cdi 的 Main 类已被修改为仅支持单个 CamelContext,这本来就是它的设计意图,但之前还保留了一些用于支持多个 Camel 的陈旧代码。方法 getCamelContextMap 和 getCamelContexts 已被移除,现在只剩下一个 getCamelContext 方法。
POJO 注解
@Consume、@Produce 和 @EndpointInject 上的 ref 属性已被移除。请改为在 uri 属性中使用 ref 组件,例如 uri = "ref:myName"。
uri 属性已被废弃,请改用 value,它支持简写形式,例如可以从 @Consume(uri = "jms:cheese") 写成 @Consume("jms:cheese")。
具有多个输入的路由
在 Camel 2.x 中,Camel 路由可以有 2 个或更多输入,但这一功能并非在所有场景下都受到支持,实际使用也很少。该功能在 Camel 2.x 中也已被废弃。在 Camel 3 中,我们移除了指定路由多输入的剩余代码,现在路由只能指定且必须指定恰好 1 个输入。
Crypto 组件
Crypto (JCE) 组件的默认签名算法已更改——现在是 SHA256withRSA(之前是 SHA1WithDSA)。
Crypto 数据格式
Crypto (JCE) 数据格式的默认加密算法已更改——现在必须为其设置值(即默认值为 null)。之前的默认值是 "DES/CBC/PKCS5Padding"。
JSon 数据格式
JSON 数据格式使用的默认 JSON 库已从 XStream 更改为 Jackson。
Shiro 组件
Shiro 组件的默认加密密钥已被移除,因此现在必须提供密钥/口令。
XML Security 组件
XML Security 组件的默认签名算法已更改——现在是 RSA-SHA256(之前是 RSA-SHA1)。
XML Security 数据格式
XML Security 数据格式的默认加密密钥已被移除,因此如果使用对称加密,现在必须提供密钥字符串/字节。这意味着那些未指定密钥就使用 XMLSecurityDataFormat 的方法已被移除。
此外,默认的对称加密算法已从三重 DES 变更为 GCM 模式的 AES-256。
Zip 和 GZip 数据格式
zip 和 gzip 数据格式已重命名为 zipdeflater 和 gzipdeflater,因为它们用于执行 zip/gzip 压缩的解压操作,而不是用于处理 zip/gzip 文件。请改用 camel-zipfile 数据格式。同时,这些数据格式已从 camel-core 中移出,转移到了 camel-zip-deflater JAR 中。XML 和 Java DSL 也已作相应修改,因此你需要同步进行迁移,改用它们的新名称。此外,如果你使用这些数据格式,还需要将 camel-zip-deflater 添加为依赖,因为它们不再作为 camel-core 的传递依赖被引入。
Simple 语言
修改 Simple 语言中用于函数起止的标记(token)的功能已被移除。默认标记 ${xxx} 和 $simple{xxx} 现在已硬编码(经过优化)。修改这些标记的功能实际上从未被使用过,如果启用新的语法,反而只会让 Camel 用户感到困惑。
已迁移的 API
以下 API 变更可能会影响你现有的 Camel 应用程序,需要进行迁移。
CamelContext
CamelContext 上与目录(catalog)相关的方法已移入到新的 CatalogCamelContext 接口中,你可以通过如下方式适配来访问它:
CatalogCamelContext ccc = context.adapt(CatalogCamelContext.class);ModelCamelContext 上的 loadRouteDefinitions 和 loadRestDefinitions 已更改为 addRouteDefinitions 和 addRestDefinitions,以与其他方法保持一致。你可以在 ExtendedCamelContext 类上找到 getModelToXMLDumper 和 getXMLRoutesDefinitionLoader 加载方法。
ModelCamelContext
如果你需要访问路由模型(例如 addRouteDefinitions 等),则需要按如下方式从 CamelContext 进行调整:
ModelCamelContext mcc = camelContext.adapt(ModelCamelContext.class);Extended CamelContext
CamelContext 上的 API 已经有所精简,以便专注于面向 Camel 最终用户的常用 API。对于高级用例以及 SPI 和组件开发者的场景,CamelContext 的部分 API 被移到了 ExtendedCamelContext 中,你可以通过 adapt 来访问它:
ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);受检异常与非受检异常
Camel 的大多数异常类已迁移为非受检异常(即继承 RuntimeException)。
此外,Service 和 SuspendableService 上 start、stop、suspend、resume 方法的生命周期也已变更,不再抛出受检异常。
通用信息
SimpleRegistry 类已从 org.apache.camel.impl 移至 org.apache.camel.support。此外,建议改用 org.apache.camel.support.DefaultRegistry。在向 SimpleRegistry 或 DefaultRegistry 添加条目时,应使用 bind 操作而非 put。
CompositeRegistry 和 PropertyPlaceholderDelegateRegistry 类已被删除,请改用 DefaultRegistry。
org.apache.camel.impl 中原本用于支持 Camel 开发者构建自定义组件的类,已从 camel-core 移出到 camel-support 的 org.apache.camel.support 包中。如果你构建过可能使用了其中某些 API 的自定义 Camel 组件,则需要进行相应的迁移。org.apache.camel.impl 包中的大部分已迁移至 camel-base 的 org.apache.camel.impl.engine 包。
org.apache.camel.util.component 中的所有类已从 camel-core JAR 移至 camel-support JAR 中的 org.apache.camel.support.component 包。
org.apache.camel.builder.AggregationStrategies 中的 xslt 方法已被移除。请改为直接使用 camel-xslt JAR 中的 XsltAggregationStrategy。
RestEndpoint 上 bindingMode 的 getter/setter 已改为使用 camel-api JAR 中的 org.apache.camel.spi.RestConfiguration.RestBindingMode 类型。除了使用该类型类之外,你也可以直接调用以字符串类型为参数的 setter 方法。
activemq-camel 组件已从 ActiveMQ 移入 Camel,现在名为 camel-activemq,相应的包名也已改为 org.apache.camel.component.activemq。
RouteBuilder 上的 includeRoutes 方法已被移除。该功能并未被完全使用,并且在 Camel 2.x 中已标记为废弃。
PredicateValidationException 异常已从包 org.apache.camel.processor.validation 移至 org.apache.camel.support.processor.PredicateValidationException。
org.apache.camel.util.toolbox.AggregationStrategies 类已移至 org.apache.camel.builder.AggregationStrategies。
org.apache.camel.util.toolbox.AggregationStrategies 类已移至 org.apache.camel.builder.AggregationStrategies。
org.apache.camel.processor.RedeliveryPolicy 类已移至 org.apache.camel.processor.errorhandler.RedeliveryPolicy。
类 org.apache.camel.processor.loadbalancer.SimpleLoadBalancerSupport 已被移除,请改用 org.apache.camel.processor.loadbalancer.LoadBalancerSupport。
类 org.apache.camel.management.JmxSystemPropertyKeys 已移动到 org.apache.camel.api.management.JmxSystemPropertyKeys。
类 org.apache.camel.builder.xml.XPathBuilder 已移动到 org.apache.camel.language.xpath.XPathBuilder,并位于 camel-xpath JAR 中。
注解 org.apache.camel.language.XPath 已移动到 org.apache.camel.language.xpath.XPath,并位于 camel-xpath JAR 中。
异常 org.apache.camel.builder.xml.InvalidXPathExpression 已重命名为 org.apache.camel.language.xpath.InvalidXPathException,并位于 camel-xpath JAR 中。
注解 org.apache.camel.language.Bean 已移动到 org.apache.camel.language.bean.Bean,并位于 camel-bean JAR 中。
注解 org.apache.camel.language.Simple 已移动到 org.apache.camel.language.simple.Simple。
注解 org.apache.camel.Constant 已被移除,请改用 @Simple。
注解 org.apache.camel.language.SpEL 已移动到 org.apache.camel.language.spel.SpEL,并位于 camel-spring JAR 中。
注解 org.apache.camel.InvokeOnHeader 和 org.apache.camel.InvokeOnHeaders 已移动到 org.apache.camel.spi 包中。
类 OutputStreamBuilder 已从包 org.apache.camel.converter.stream 移动到 org.apache.camel.support.builder 包。
重命名了 camel-core 中的多个 API,将拼写错误 chiper 修正为 cipher。
类 ReloadStrategySupport 和 FileWatcherReloadStrategy 已被移除。
MessageHistoryFactory 接口增加了用于过滤和复制消息的一些选项,其 API 也有轻微变化。
已移除 TypeConverterAware,你应当改为在类型转换方法中使用 Exchange 作为参数。
Component 和 DataFormat 接口现在继承自 Service,因为组件和数据格式也应具备服务契约以管理其生命周期。默认的基础类已经实现了这些接口。
FactoryFinder 类的 API 已改为使用 Optional 作为返回类型,而不再抛出受检的 FactoryNotFoundException、ClassNotFoundException 等异常。
所有组件上的 resolvePropertyPlaceholders 选项已被移除,因为属性占位符已经通过 Camel Main、Camel Spring Boot 以及其他方式得到支持。
camel-test
如果你正在使用 camel-test 并重写了 createRegistry 方法(例如用于注册 JndiRegistry 类中的 Bean),那么现在已不再必要,你应当改为使用 Registry API 中的 bind 方法,该方法可以直接从 CamelContext 调用,例如:
context.getRegistry().bind("myId", myBean);控制路由
CamelContext 上的 startRoute、stopRoute、suspendRoute、resumeRoute、getRouteStatus 以及其他相关方法已移至 RouteController,如下所示:
context.getRouteController().startRoute("myRoute");JMX 事件
来自 org.apache.camel.management.event 包的所有事件已作为子类移至 org.apache.camel.spi.CamelEvent 类中,例如 CamelContext 启动事件将变为 CamelEvent.CamelContextStartedEvent。
AdviceWith
目前使用 adviceWith 进行测试需要从如下写法改为:
context.getRouteDefinition("start").adviceWith(camelContext, new AdviceWithRouteBuilder() {
...
}改为使用 style:
ModelCamelContext mcc = camelContext.adapt(ModelCamelContext.class);
RouteReifier.adviceWith(mcc.getRouteDefinition("start"), mcc, new AdviceWithRouteBuilder() {
...
}不过,使用 lambda 风格配合 AdviceWithRouteBuilder 更加简单:
AdviceWith.adviceWith(context, "myRoute", a -> {
a.replaceFromWith("direct:start");
}泛型类
类 JNDIContext 已从 camel-core JAR 中的 org.apache.camel.util.jndi.JNDIContext 移动到 org.apache.camel.support.jndi.JNDIContext,并迁移到了 camel-support JAR。
企业集成模式(EIP)
circuitBreaker 负载均衡 EIP 在 Camel 2.x 中已被弃用,并已被移除。请改用 Hystrix EIP 作为负载均衡器。
类 ThreadPoolRejectedPolicy 已从 org.apache.camel.ThreadPoolRejectedPolicy 移动到 org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy。
语言
simple 语言的 property 函数在 Camel 2.x 中已被弃用,并已被移除。请使用 exchangeProperty 作为函数名。
terser 语言已从 terser 重命名为 hl7terser。
JSSE
org.apache.camel.util.jsse 中的类已移动到 org.apache.camel.support.jsse。
辅助类与支持类
类 AsyncProcessorHelper 已从 camel-core JAR 中的 org.apache.camel.util.AsyncProcessorHelper 移动到 org.apache.camel.support.AsyncProcessorHelper,并迁移到了 camel-support JAR。
类 AsyncProcessorConverterHelper 已从 camel-core JAR 中的 org.apache.camel.util.AsyncProcessorConverterHelper 移动到 org.apache.camel.support.AsyncProcessorConverterHelper,并迁移到了 camel-support JAR。
类 CamelContextHelper 已从 camel-core JAR 中的 org.apache.camel.util.CamelContextHelper 移动到 org.apache.camel.support.CamelContextHelper,并迁移到了 camel-support JAR。
类 EndpointHelper 已从 camel-core JAR 中的 org.apache.camel.util.EndpointHelper 移动到 org.apache.camel.support.EndpointHelper,并迁移到了 camel-support JAR。
类 EventHelper 已从 camel-core JAR 中的 org.apache.camel.util.EventHelper 移动到 org.apache.camel.support.EventHelper,并迁移到了 camel-support JAR。
类 ExchangeHelper 已从 camel-core JAR 中的 org.apache.camel.util.ExchangeHelper 移动到 org.apache.camel.support.ExchangeHelper,并迁移到了 camel-support JAR。
类 GZIPHelper 已从 camel-core JAR 中的 org.apache.camel.util.GZIPHelper 移动到 org.apache.camel.support.GZIPHelper,并迁移到了 camel-support JAR。
类 JsonSchemaHelper 已从 camel-core JAR 中的 org.apache.camel.util.JsonSchemaHelper 移动到 org.apache.camel.support.JsonSchemaHelper,并迁移到了 camel-support JAR。
类 MessageHelper 已从 camel-core JAR 中的 org.apache.camel.util.MessageHelper 迁移到 org.apache.camel.support.MessageHelper,并移至 camel-support JAR。
类 ObjectHelper 已从 camel-core JAR 中的 org.apache.camel.util.ObjectHelper 拆分而来,一部分迁移到 org.apache.camel.support.ObjectHelper 并移至 camel-support JAR,另一部分迁移到 org.apache.camel.util.ObjectHelper 并移至 camel-util JAR。这样做是为了隔离使用 camel-api JAR 的方法:这些方法位于 camel-support JAR 中,其余方法位于 camel-util JAR 中。
类 PlatformHelper 已从 camel-core JAR 中的 org.apache.camel.util.PlatformHelper 迁移到 org.apache.camel.support.PlatformHelper,并移至 camel-support JAR。
类 PredicateAssertHelper 已从 camel-core JAR 中的 org.apache.camel.util.PredicateAssertHelper 迁移到 org.apache.camel.support.PredicateAssertHelper,并移至 camel-support JAR。
类 ResolverHelper 已从 camel-core JAR 中的 org.apache.camel.util.ResolverHelper 迁移到 org.apache.camel.support.ResolverHelper,并移至 camel-support JAR。
类 ResourceHelper 已从 camel-core JAR 中的 org.apache.camel.util.ResourceHelper 迁移到 org.apache.camel.support.ResourceHelper,并移至 camel-support JAR。
类 RestProducerFactoryHelper 已从 camel-core JAR 中的 org.apache.camel.spi.RestProducerFactoryHelper 迁移到 org.apache.camel.support.RestProducerFactoryHelper,并移至 camel-support JAR。
类 ServiceHelper 已从 camel-core JAR 中的 org.apache.camel.util.ServiceHelper 迁移到 org.apache.camel.support.service.ServiceHelper,并移至 camel-api JAR。
类 UnitOfWorkHelper 已从 camel-core JAR 中的 org.apache.camel.util.UnitOfWorkHelper 迁移到 org.apache.camel.support.UnitOfWorkHelper,并移至 camel-support JAR。
幂等仓储
类 FileIdempotentRepository 已从 camel-core JAR 中的 org.apache.camel.processor.idempotent.FileIdempotentRepository 迁移到 org.apache.camel.support.processor.idempotent.FileIdempotentRepository,并移至 camel-support JAR。
类 MemoryIdempotentRepository 已从 camel-core JAR 中的 org.apache.camel.processor.idempotent.MemoryIdempotentRepository 迁移到 org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository,并移至 camel-support JAR。
路由策略
类 org.apache.camel.support.RoutePolicySupport 已移至 camel-support JAR。startConsumer 和 stopConsumer 的返回类型已从 boolean 更改为 void,因为它们之前总是返回 true。
类 org.apache.camel.impl.ThrottlingInflightRoutePolicy 已移动到 org.apache.camel.throttling.ThrottlingInflightRoutePolicy。
聚合(Aggregation)
类 XsltAggregationStrategy 已从 camel-core JAR 中的 org.apache.camel.util.toolbox.XsltAggregationStrategy 移动到 org.apache.camel.component.xslt.XsltAggregationStrategy,并迁移到 camel-xslt JAR 中。
在聚合器 EIP 上使用 groupedExchange 选项时,聚合结果不再同时存储到交换属性 Exchange.GROUPED_EXCHANGE 中。此行为自 Camel 2.13 起已被废弃。
回退类型转换器
@FallbackConverter 注解已被移除,应改用 @Converter(fallback = true)。同时,可以在转换器类上设置 @Converter(generateLoader = true),让 Camel 以更快的方式生成加载类型转换器的源代码。
用于解释 EIP、组件等内容的 JMX API 已移除
用于查找和解释 EIP、组件、端点等内容的 API 已被移除。这些 API 对生产运行时价值不大,你可以通过 camel-catalog 获取此类信息。使用这些 API 的相关 Camel Karaf 命令也已被移除。
其他变更
使用面包屑(breadcrumbs)的默认值已从 true 改为 false。
如果 CamelContext 尚未启动,ProducerTemplate 和 ConsumerTemplate 在使用时将抛出失败。
XML DSL 迁移
XML DSL 发生了一些细微变化。
自定义负载均衡 EIP 从 <custom> 改为 <customLoadBalancer>。
XMLSecurity 数据格式在 <secureXML> 标签中将属性 keyOrTrustStoreParametersId 重命名为 keyOrTrustStoreParametersRef。
<zipFile> 数据格式已重命名为 <zipfile>。
迁移 Camel Maven 插件
camel-maven-plugin 已拆分为两个 Maven 插件:
- camel-maven-plugin
- camel-report-maven-plugin
前者提供了 run 目标,用于快速独立运行 Camel 应用程序。
camel-report-maven-plugin 提供了 validate 和 route-coverage 目标,用于生成 Camel 项目的报告,例如验证 Camel 端点 URI、生成路由覆盖率报告等。
已知问题
由于内部路由引擎的重构,在通过异步端点进行路由的某些场景下,MDC 日志无法正确传递 Camel breadcrumb id。此项变更也会影响 camel-zipkin 组件——在使用 MDC 日志时,它可能同样无法正确传递 span id。
评论
登录后参与评论
KnowForge