简体   繁体   English

如何在不同骆驼路线的方法之间共享对象

[英]How to share an object between methods on different camel routes

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. 我要做的就是在骆驼路由中调用的方法中创建一个HashSet,然后将此HashSet传递给另一骆驼路由中的方法。
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. 第一个路由中的方法“ findProperties”创建一个HashSet,我想在“ parseFile”方法的第二个路由中使用它。

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... 因为您的第一个路由不会调用您的第二个路由,所以它们之间没有消息传递来传递数据...所以是的,您需要使用一些外部方法来访问在路由/线程之间共享的数据...

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 这可以很简单,就像您的ParserUtils实例中的类/静态级别变量一样,也可以使用骆驼缓存 (ehcache等), 骆驼hazelcast等...选择由您选择

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.java https://svn.apache.org/repos/asf/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java

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

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