Camel Context上的Threadpool配置(Threadpool configuration on Camel Context)
我创建了多个camelContexts,并希望每个camelContext都使用自己的自定义线程池。 但是,日志显示我的所有camelContexts都使用相同的线程池。 我错过了什么?
主要骆驼语境
<camelContext id="routeLoader_route"> (no threadpool defined) <route id="RouteCreator" > <from uri="file://jsonFilePath" /> <bean ref="routeMonitor" method="loadJsontoCreateRoute" /> </route> (some other routes defined) </camelContext>
方法“loadJsontoCreateRoute”将读取三个json文件,然后创建三个要连接的路由
- 端点“file:// xxx1 / out”到端点“direct-vm:out.test”
- 端点“file:// xxx2 / out”到端点“direct-vm:out.test”
- 端点“file:// xxx3 / out”到端点“direct-vm:out.test”
另一个骆驼背景
<camelContext id="test_out_route"> <threadPoolProfile id="outTestThreadPoolProfile" defaultProfile="true" poolSize="1" maxPoolSize="1" maxQueueSize="1000" rejectedPolicy="CallerRuns"/> <route id="outboundTestingRouter"> <from uri="direct-vm:out.test"/> <doTry> <log message="Outbound Test -- START" loggingLevel="INFO" /> <recipientList> <method ref="outTestBean" method="dynamicRoute" /> </recipientList> <doFinally> <log message="Outbound Test-- END" loggingLevel="INFO" /> <stop/> </doFinally> </doTry> </route> (Some other routes defined) </camelContext>
dynamicRoute方法将为ftp组件返回一个uri
日志
20160623 09:48:04.297 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.524 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.526 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.527 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.634 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.636 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.652 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.653 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.749 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.749 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.827 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.827 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.890 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.937 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.937 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.999 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.140 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.358 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.358 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.469 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.471 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.593 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.905 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.999 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END
日志的第3行到第10行显示有多个outboundTestingRouter路由同时运行,而我的threadpool outTestThreadPoolProfile池大小限制为1
这表明outboundTestingRouter路由没有使用线程池outTestThreadPoolProfile
我想要的是限制最大值。 route outboundTestingRouter的并发使用次数。
I have multiple camelContexts created and would like each camelContext to use their own custom threadpool. However, the log shows all my camelContexts are using the same threadpool. What am I missing?
Main Camel Context
<camelContext id="routeLoader_route"> (no threadpool defined) <route id="RouteCreator" > <from uri="file://jsonFilePath" /> <bean ref="routeMonitor" method="loadJsontoCreateRoute" /> </route> (some other routes defined) </camelContext>
The method "loadJsontoCreateRoute" will read three json files and then create three routes to connect from
- endpoint "file://xxx1/out" to endpoint "direct-vm:out.test"
- endpoint "file://xxx2/out" to endpoint "direct-vm:out.test"
- endpoint "file://xxx3/out" to endpoint "direct-vm:out.test"
Another camel context
<camelContext id="test_out_route"> <threadPoolProfile id="outTestThreadPoolProfile" defaultProfile="true" poolSize="1" maxPoolSize="1" maxQueueSize="1000" rejectedPolicy="CallerRuns"/> <route id="outboundTestingRouter"> <from uri="direct-vm:out.test"/> <doTry> <log message="Outbound Test -- START" loggingLevel="INFO" /> <recipientList> <method ref="outTestBean" method="dynamicRoute" /> </recipientList> <doFinally> <log message="Outbound Test-- END" loggingLevel="INFO" /> <stop/> </doFinally> </doTry> </route> (Some other routes defined) </camelContext>
The dynamicRoute method will return a uri for ftp component
Log
20160623 09:48:04.297 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.524 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.526 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.527 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.634 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.636 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.652 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.653 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.749 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.749 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.827 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.827 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.890 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.937 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:04.937 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:04.999 [Camel (routeLoader_route) thread #24 - file://xxx3/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.140 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.358 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.358 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.469 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.471 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.593 [Camel (routeLoader_route) thread #5 - file://xxx1/out] INFO outboundTestingRouter - Outbound Test -- END 20160623 09:48:05.905 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- START 20160623 09:48:05.999 [Camel (routeLoader_route) thread #17 - file://xxx2/out] INFO outboundTestingRouter - Outbound Test -- END
Line 3 to line 10 of the log shows that there is more than 1 outboundTestingRouter route is concurrently running while my threadpool outTestThreadPoolProfile pool size is limit to 1
This indicates that the threadpool outTestThreadPoolProfile is not being used by outboundTestingRouter route
What I do want is to limit the max. number of concurrent usage of route outboundTestingRouter.
原文:https://stackoverflow.com/questions/37961171
最满意答案
第1部分:你正在使用lat / lon,在neo4j 3.0中有点和距离的原生支持,请确保使用
latitude
和longitude
属性键。 然后,您可以使用以下内容在关系上设置此属性:MATCH (start:YourNodeLabel)-[r:NEXT]->(end) SET r.distance = distance(point(start), point(end)) / 1000
第2部分:如果您知道路径的开始和结束节点,则可以通过减少关系的距离属性来创建下一个关系:
MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH (start)-[r:NEXT*]->(end) CREATE (start)-[newrel:NEXT]->(end) SET newrel.distance = reduce(d=0.0, x IN r | d + x.distance)
但要注意这一点,考虑到从
start
到end
可能有多条path
,在这种情况下,例如,如果你想找到从开始到结束的最短距离,你需要计算总距离并采取最低的一个:MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH p=(start)-[:NEXT*]->(end) WITH p, start ,end, reduce(d=0.0, x IN rels(p) | d + x.distance) as totalDistance ORDER BY totalDistance ASC LIMIT 1 CREATE (start)-[newRel:NEXT]->(end) SET newRel.distance = totalDistance
如果关系中没有距离属性,还可以在reduce函数中动态计算地理距离:
MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH p=(start)-[:NEXT*]->(end) WITH p, start, end, reduce(d=0.0, x IN range(1, size(nodes(p))-1) | d + distance(point(nodes(p)[x-1]), point(nodes(p)[x])) / 1000) as distance ORDER BY distance ASC LIMIT 1 CREATE (start)-[newRel:NEXT]->(end) SET newRel.distance = distance
作为一般建议,我不会对用作快捷方式的关系使用相同的关系类型名称,可能更适合
CONNECT_TO
或REACH_POINT
以便不干扰其他查询中的NEXT
关系。Part1 : You're using lat/lon, in neo4j 3.0 there is native support for point and distance, make sure to use
latitude
andlongitude
property keys. You can then set this property on the relationship with the following :MATCH (start:YourNodeLabel)-[r:NEXT]->(end) SET r.distance = distance(point(start), point(end)) / 1000
Part 2 : If you know the start and end node of the path, you can then create this next relationship by reducing the distance properties of the relationships :
MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH (start)-[r:NEXT*]->(end) CREATE (start)-[newrel:NEXT]->(end) SET newrel.distance = reduce(d=0.0, x IN r | d + x.distance)
Be careful however with this, taking into account that there could be more than one
path
fromstart
toend
, in that case for eg if you want to find the shortest distance from start to end, you will need to calculate the total distance and take the lowest one :MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH p=(start)-[:NEXT*]->(end) WITH p, start ,end, reduce(d=0.0, x IN rels(p) | d + x.distance) as totalDistance ORDER BY totalDistance ASC LIMIT 1 CREATE (start)-[newRel:NEXT]->(end) SET newRel.distance = totalDistance
If you don't have the distance properties on the relationships, you can also calculate the geo distance on the fly in the reduce functions :
MATCH (start:YourNodeLabel {name:"A"}), (end:YourNodeLabel {name:"E"}) MATCH p=(start)-[:NEXT*]->(end) WITH p, start, end, reduce(d=0.0, x IN range(1, size(nodes(p))-1) | d + distance(point(nodes(p)[x-1]), point(nodes(p)[x])) / 1000) as distance ORDER BY distance ASC LIMIT 1 CREATE (start)-[newRel:NEXT]->(end) SET newRel.distance = distance
As a general advise, I wouldn't use the same relationship type name for the relationship used as a shortcut, maybe
CONNECT_TO
orREACH_POINT
can be more suited in order to not to interfer with theNEXT
relationships in other queries.
相关问答
更多-
如果它是从最后一个绘制点到鼠标点的直线,那么使用基本数学= SQRT((x1-x2)^ 2 +(y1-y2)^ 2) 唯一的技巧是从屏幕坐标转换为用户坐标。 这是我使用的功能非常好(到目前为止)... function getMousePos(evt) { var svgPoint = document.documentElement.createSVGPoint(); evt = evt || window.event; if (typeof evt.pageX != 'un ...
-
在路径上合并节点计算关系的(复合)属性(Merging Nodes on Path calculating a (compound) Properties of the relationship)[2023-07-11]
第1部分:你正在使用lat / lon,在neo4j 3.0中有点和距离的原生支持,请确保使用latitude和longitude属性键。 然后,您可以使用以下内容在关系上设置此属性: MATCH (start:YourNodeLabel)-[r:NEXT]->(end) SET r.distance = distance(point(start), point(end)) / 1000 第2部分:如果您知道路径的开始和结束节点,则可以通过减少关系的距离属性来创建下一个关系: MATCH (start:Y ... -
您可以使用reduce来组合数组: WITH path, extract(n IN nodes(path)| n.name) as names, extract(r IN relationships(path)| r.metric) as metrics RETURN HEAD(names) + REDUCE(acc = [], i in RANGE(1,size(metrics)) | acc + metrics[i-1] + names ...
-
确保导致禁止节点的所有边都具有无限的成本,并且您使用的任何图遍历算法都会自动处理。 或者,只需删除图表遍历算法考虑的禁止节点即可。 Make sure all edges that would lead to the forbidden node(s) have an infinite cost, and whichever graph-traversing algorithm you use will deal with it automatically. Alternatively, just remo ...
-
Cypher:如何匹配路径中的关系节点关系(Cypher: How to match relationship-node-relationship within a path)[2023-12-08]
你很亲密! 如您所知, *表示可变长度/深度。 您可以像在查询中一样使用该符号,也可以指定范围。 没有指定范围, *表示“一个或多个”。 如果您应用上一个查询 MATCH (a)-[*]-(b)-[:RED]->(findme)<-[:RED]-(c)-[*]-(x) WHERE a.name = "a" AND x.name = "x" RETURN findme 到三个节点的路径 (a)-[:RED]->(findme)<-[:RED]-(x) 路径中的两个关系可以与查询的非可变部分匹配。 但是,没 ... -
neo4j中的复合关系(Compound relationship in neo4j)[2022-09-12]
认为“婚姻”是您所在领域的重要组成部分。 作为实体的任何东西都应该有一个单独的节点 - 因此“婚姻”(或“事件”)成为一个节点。 然后该节点可以连接到两个人和位置。 Consider "Marriage" being a vital part of your domain. Anything being an entity deserves a separate node - so "Marriage" (or Event) becomes a node. That node then can be con ... -
我怕你在这里做不了多少。 您的图表非常具体,只与最近的节点有关系。 这太糟糕了,因为neo4j可以在起点附近玩+ - 很少有关系,而不是每个查询的整个图表 这意味着,一旦你离开2个节点,计算复杂度就会提高到: 8 relationships per node distance 2 8 + 8^2 通常,距离n的最高复杂度是 O(8 + 8^n) //in case all affected nodes have 8 connections 你说,你有~80 000个节点。这意味着(纠正我,如果我错了), ...
-
以下是Cypher提供的查询: MATCH p = (c:Customer {Galactic_ID : "1000000000275162734"}) - [r:Customer_Send|:Customer_used_ID|:Customer_used_Phone*1..5] - () WITH distinct(p) as p,[node IN NODES(p) WHERE node:Customer] AS customer_nodes UNWIND customer_nodes AS c_node ...
-
您可以通过WITH将“p”传递给查询的下一部分: START n=node(10200) MATCH p=(n)-[r*1..5]->(m:Facility) WITH REDUCE(weights=0, rel IN r : weights + rel.weight) AS weight_sum, p WHERE ALL(n in nodes(p) WHERE 1=length(filter(m in nodes(p) : m=n))) RETURN p AS paths, length(p) AS ...
-
确保使用标签+索引快速查找开始和结束节点。 如果使用最短路径,则只找到一条路径。 match p=shortestPath((n:Label)-[r:rel1*..]->(m:Label) where n.nodeNumber = 1 and m.nodeNumber=1000 RETURN extract(n IN nodes(p) | {name: n.name, value: head([p in (n)<-[:rel2]-() | last(nodes(p)).value]) ) AS dat ...