gpt4 book ai didi

scala - Apache Camel 文件进程导致类型转换错误

转载 作者:行者123 更新时间:2023-12-04 17:41:04 24 4
gpt4 key购买 nike

我正在使用 akka-camel 来处理文件。我的初始测试运行良好,但是当我开始传递实际的 xml 文件时,它因类型转换而呕吐。

这是我的消费者(非常简单,但在 msg.bodyAs[String] 处呕吐

class FileConsumer extends Consumer {
def endpointUri = "file:/data/input/actor"

val processor = context.actorOf(Props[Processor], "processor")

def receive = {
case msg: CamelMessage => {
println("Parent...received %s" format msg)
processor ! msg.bodyAs[String]
}
}
}

错误:

[ERROR] [04/27/2015 12:10:48.617] [ArdisSystem-akka.actor.default-dispatcher-5] [akka://ArdisSystem/user/$a] Error during type conversion from type: org.apache.camel.converter.stream.FileInputStreamCache to the required type: java.lang.String with value org.apache.camel.converter.stream.FileInputStreamCache@4611b35a due java.io.FileNotFoundException: /var/folders/dh/zfqvn9gn7cl6h63d3400y4zxp3xtzf/T/camel-tmp-807558/cos2920459202139947606.tmp (No such file or directory)
org.apache.camel.TypeConversionException: Error during type conversion from type: org.apache.camel.converter.stream.FileInputStreamCache to the required type: java.lang.String with value org.apache.camel.converter.stream.FileInputStreamCache@4611b35a due java.io.FileNotFoundException: /var/folders/dh/zfqvn9gn7cl6h63d3400y4zxp3xtzf/T/camel-tmp-807558/cos2920459202139947606.tmp (No such file or directory)

我想知道它是否与 xml 的实际内容有关。它们一点也不大(大约 70kb)。我怀疑我能否提供 XML 本身的实际示例。只是困惑为什么这么小的东西被转换成字符串会出现问题。其他虚拟示例 xml 文件运行良好。

编辑:我的建议之一是启用 StreamCache,我照做了。但是,它似乎仍然没有用。正如 Ankush 评论的那样,错误令人困惑。我不确定它是否真的是一个 Stream 问题,或者它是否真的是一个转换问题。

http://camel.apache.org/stream-caching.html

添加了以下内容

  camel.context.setStreamCaching(true)

最佳答案

我终于弄清楚了问题所在。问题不是坏数据,而是文件的大小。为了解决这个问题,您需要向 camel 上下文添加其他设置。

http://camel.apache.org/stream-caching.html

我使用的设置如下。如果我应该关闭流缓存,我将需要进一步研究,但这是一个开始。

camel.context.getProperties.put(CachedOutputStream.THRESHOLD, "750000");

或关闭流缓存

 camel.context.setStreamCaching(false)

希望这对其他人有帮助。

关于scala - Apache Camel 文件进程导致类型转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com