Sitnikov Artem
Sitnikov Artem

Reputation: 43

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

Upvotes: 2

Views: 4522

Answers (2)

the hand of NOD
the hand of NOD

Reputation: 1769

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
    

Upvotes: 1

Claus Ibsen
Claus Ibsen

Reputation: 55525

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.

Upvotes: 5

Related Questions