[英]How to find all Endpoints of route (Apache Camel, Java)
在駱駝語境中,我有幾條路線和許多終點。 因此需要獲取由一個路由創建的所有端點:
CamelContext context = new DefaultCamelContext();
RouteBuilder route1 = new RouteBuilder() {
public void configure() {
from("file:data/inbox?noop=true")
.routeId("myRoute1")
.enrich("http://website.com/file.txt")
.to("file:data/outbox")
.to("mock:someway");
}
};
RouteBuilder route2 = new RouteBuilder() {
public void configure() {
from("file:data/outbox?noop=true")
.routeId("myRoute2")
.to("mock:myMom");
}
};
context.addRoutes(route1);
context.addRoutes(route2);
context.start();
// TODO
context.stop();
在停止之前,我需要獲取由myRoute1創建的所有端點? 例如:
1.file:// data / outbox 2.mock:// someway 3. http://website.com/file.txt 4.file:// data / inbox?noop = true
我只能將駱駝上下文的所有端點獲取為:context.getEndpoints()
端點不與單個路由關聯,因為它可以在多個路由之間重用。 因此,您無法真正從端點本身中找出答案。 但是,您可以做的是在添加路由之前將所有端點存儲在本地列表中,然后再獲取所有端點,然后比較這兩個端點列表。 然后通過新路由添加所有新端點。
您可以嘗試以下方法:
從CamelContext的Route中獲取RouteDefinition,並過濾ToDefinition對象的輸出列表。
List<ProcessorDefinition> outputProcessorDefs = exchange.getContext().getRouteDefinition("[routeId]").getOutputs(); // Iterate and get all ProcessorDefinition objects which inherit from the ToDefinition
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.