简体   繁体   中英

How to find all Endpoints of route (Apache Camel, Java)

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()

An endpoint is not associated to a single route, as it can be reused among multiple routes. So you cannot really find out from the endpoint itself. But what you can do is to store all the endpoints in a local list, before you add the route, and then afterwards get all the endpoints again, and then diff these 2 lists of endpoints. all the new endpoints was then added by the new route.

You could try the following:

  1. Give your route an routeId to be able to identify it later.
  2. Get the RouteDefinition from the Route from the CamelContext and filter the List of Outputs for the ToDefinition objects.

      List<ProcessorDefinition> outputProcessorDefs = exchange.getContext().getRouteDefinition("[routeId]").getOutputs(); // Iterate and get all ProcessorDefinition objects which inherit from the ToDefinition 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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