简体   繁体   English

Apache Camel-指定要使用的转换器

[英]Apache Camel - Specify which converter to use

I would like to define two different converters methods for Camel that would take the same Object class and return the same Object class. 我想为Camel定义两个不同的转换器方法,这些方法将采用相同的Object类并返回相同的Object类。

@Converter
public static Exchange fromStreamSourceToExchangeList1(StreamSource ss)

@Converter
public static Exchange fromStreamSourceToExchange2(StreamSource ss)

The issue is when I try to call my converter I can't specify which one to be used, only the desired types: 问题是当我尝试调用转换器时,我无法指定要使用的转换器,只能指定所需的类型:

from(starter).routeId(Feed).to(uri).convertBodyTo(StreamSource.class).convertBodyTo(Exchange.class).process(..)

How can I specify a converter using convertBodyTo? 如何使用convertBodyTo指定转换器?

Camel only supports 1 type converter per from -> to. 骆驼每个->至仅支持1种类型的转换器。 So this is not supported. 因此不支持此功能。 When Camel startup and it detects 2+ of the same type converters you get a WARN logging and the last override the oldest (I think that is the default behaviour, but you can re-configure what to do). 当Camel启动并检测到2个以上相同类型的转换器时,您将得到WARN日志记录,并且最后一个覆盖最旧的(我认为这是默认行为,但是您可以重新配置该怎么做)。

So in this case, then do NOT use type converters, but use bean method calls, and call the method with the conversion you want. 因此,在这种情况下,请不要使用类型转换器,而要使用bean方法调用,并使用所需的转换来调用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM