I have several routes and many endpoints in Camel context. So need to get all endpoints created by one Route:
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();
And before stop I need get all endpoints which created by myRoute1 ??? for example:
1.file://data/outbox
2.mock://someway
3.http://website.com/file.txt
4.file://data/inbox?noop=true
I can get only all Endpoints of Camel context as: context.getEndpoints()
解决方案
You could try the following:
Give your route an routeId to be able to identify it later.
Get the RouteDefinition from the Route from the CamelContext and filter the List of Outputs for the ToDefinition objects.
List outputProcessorDefs = exchange.getContext().getRouteDefinition("[routeId]").getOutputs();
// Iterate and get all ProcessorDefinition objects which inherit from the ToDefinition