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

问题描述

我在网上搜索没有运气的东西,我认为这很简单,但显然不是。

我想要做的就是在一个被调用的方法中创建一个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实例中的类/静态级别变量一样简单,也可以使用(ehcache等),等......选择权在你身边

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

这里有一些使用camel-cache的例子......

here are some examples using camel-cache...

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

09-22 23:46