Which Camel construct is suited for transforming?(哪种 Camel 构造适合转换?)
问题描述
Apache Camel 提供了几种执行数据转换的方法:其转换 EIP 的概念、自定义数据格式以及允许自定义类型转换器.
Apache Camel offers several ways of performing data transforms: its concept of the Transform EIP, custom DataFormats, as well as its allowance for custom Type Converters.
我有一种情况,我需要从 Camel 路线内部进行非常复杂的转换.我应该实现我自己的类型转换器、我自己的 DataFormat,还是应该实现 org.apache.camel.Expression
并将所有转换的东西放在那里:
I have a situation where I need to do a very complex transform from inside a Camel route. Should I be implementing my own Type Converter, my own DataFormat, or should I implement org.apache.camel.Expression
and put all the transform stuff in there:
public class MyTransformer implements Expression {
@Override
public <T> T evaluate(Exchange arg0, Class<T> arg1) {
// ...
}
}
我想我对何时/何时使用您自己的类型转换器、何时使用 .transform(myTransformer)
处理器或何时使用自定义 DataFormat 感到困惑.提前致谢!
I guess I'm confused about where/when it's appropriate to use your own Type Converter, when to use the .transform(myTransformer)
processor, or when to use a custom DataFormat. Thanks in advance!
推荐答案
虽然它们都用于不同的事情,但它们的区别是微妙的.你应该使用:
The differences are subtle, though they are all used for different things. You should use:
- a transformer 当您将业务负载"从一种形状转换为另一种形状时.例如,当您将从 DAO 中提取的值对象转换为您将用于调用 Web 服务的 JAXB 注释对象时.
- a 数据格式,当您想要编组高级表示时,例如某种类型的对象,转换为较低级别的表示 - 您将通过电线发送的东西.数据格式包括序列化、Google 协议缓冲区、JSON、JAXB 等.
- a 类型转换器,当您更改访问消息表示的方式时.例如.一个字符串和一个字节数组或一个 InputStream 仍然读取相同的字符,因此您可以在那里编写(尽管实际上有内置的)转换器来在其中任何两个之间进行转换.
- a transformer when you are converting a "business payload" from one shape to another. For example, when you are converting value objects that you pulled from a DAO into JAXB annotated objects that you are going to use to invoke a webservice.
- a data format when you want to marshall an high-level representation, such as some type of Object, into a lower level representation - something that you would send over a wire. Data formats include serialization, Google protocol buffers, JSON, JAXB etc.
- a type converter when you are changing the way you access a representation of a message. E.g. a String and a byte array or an InputStream still read the same characters, so there you might write (though there actually are built-in) converters that convert between any two of these.
这篇关于哪种 Camel 构造适合转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:哪种 Camel 构造适合转换?
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01