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 构造适合转换?
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01