哪种Camel构造适合转换? [英] Which Camel construct is suited for transforming?

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

问题描述

Apache Camel提供了几种执行数据转换的方法:Transform EIP的概念,自定义DataFormats,以及自定义类型转换器的允许。

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路线内部进行非常复杂的变换。我应该实现自己的Type Converter,我自己的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:


  • 变压器当您将业务负载从一种形状转换为另一种形状时。例如,当您将从DAO中提取的值对象转换为您将用于调用Web服务的JAXB注释对象时。

  • a 数据格式当您想要将高级表示(例如某种类型的对象)编组到较低级别的表示中时 - 您将发送的内容一条电线。数据格式包括序列化,Google协议缓冲区,JSON,JAXB等。

  • 类型转换器当您更改访问邮件表示的方式时。例如。一个字符串和一个字节数组或一个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构造适合转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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