How can be able to listen to the events of one route by another route in Apache Camel

48 views Asked by At

I am having an issue while working on the requirement. The requirement is I am having 2 routes. One route is just to listen the events generated by 2nd route and aggregates them and push it to destination for every 10 mins.

Route1 looks like below :

- from:
    uri: "spring-event:foo"
    steps:
     - to: "log:result"

Route 2 looks like below:

 - from:
     uri: "direct:foo1"
     steps:
      - to: "direct:dest"

The order of running the routes is, First run the route1 which keeps on listening for the events(will not stop) and then run the route2 which does its work and logs the events while executing this route. Both the pipelines are in same application. I want these logged events to be listened by route1 and aggregates them and sent to destination for every 10 mins.

I am handling the events by writing the generic class file which handles the events for every pipeline it runs. The generic class looks like this:

class EventHandler extends EventNotfierSupport{

  @Override
  public void notify(CamelEvent event){
   if(event.getType() == "RoutesStarted"){
     // logs the properties related to event
   } else if(event.getType() == "ExchangeSent"){
    // logs the properties related to event
      
    } else if(event.getType() == "RoutesStopped"){
     
       // logs the properties related to event
    }
 
    // some other events are handled.
   
  }
  
}

I want these properties which are being logged per event has to be listened by route1 and aggregated them and send to dest for every 10 mins.

0

There are 0 answers