如何在不同骆驼路线上的方法之间共享对象 [英] How to share an object between methods on different camel routes

查看:26
本文介绍了如何在不同骆驼路线上的方法之间共享对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了一些我认为很简单但显然不是的东西.
我想要做的就是在骆驼路由中调用的方法中创建一个 HashSet,然后将此 HashSet 传递给另一个骆驼路由中的方法.
我的搜索返回的是我应该使用缓存,但我找不到任何示例(一个简单的示例)来告诉我如何实现它.
第一个路由中的方法findProperties"创建了一个 HashSet,我想在parseFile"方法的第二个路由中使用它.

I am search the web without luck about something I thought would be simple but apparently it is not.
All I want to do is to do, is create a HashSet in a method that is called in a camel route and then pass this HashSet to a method in another camel route.
What my search returned is that I should use a cache but I can't find any example (a simple one) that will show me how implement this.
Method "findProperties" in first route creates a HashSet which I want to use in the second route in "parseFile" method.

from("file:{{List}}?noop=true")
.autoStartup(true)
.unmarshal().csv()
.to("bean:ParserUtils?method=findProperties")
.end();


from("file:{{Path}}?move={{processedPath}}")
.autoStartup(true)
.unmarshal().csv()
.to("bean:Parser?method=parseFile")
.end()

我真的很感激在缓存中获取和设置对象的简单示例或其他解决方案.

I would really appreciate a simple example of getting and setting an object in cache or another solution maybe.

推荐答案

因为你的第一个路由没有调用你的第二个路由,所以它们之间没有消息传递数据......所以是的,你需要使用一些访问在路由/线程之间共享的数据的外部手段...

since your first route doesn't invoke your second route, there is no messaging between them to pass data around...so yes, you need to use some external means to access data that is shared between routes/threads...

这可以像 ParserUtils 实例中的类/静态级别变量一样简单,也可以使用 camel-cache(ehcache 等)、camel-hazelcast 等...是你的

this can be as simple as a class/static level variable in your ParserUtils instance or using camel-cache (ehcache, etc), camel-hazelcast, etc...the choice is yours

这里有一些使用骆驼缓存的例子...

here are some examples using camel-cache...

https://svn.apache.org/repos/asf/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.爪哇

这篇关于如何在不同骆驼路线上的方法之间共享对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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