哪种骆驼结构适合转化? [英] Which Camel construct is suited for transforming?

查看:26
本文介绍了哪种骆驼结构适合转化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 路由内部进行非常复杂的转换.我应该实现自己的类型转换器、自己的数据格式,还是应该实现 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:

  • 转换器,当您将业务负载"从一种形状转换为另一种形状时.例如,当您将从 DAO 中提取的值对象转换为要用于调用网络服务的 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.

这篇关于哪种骆驼结构适合转化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆