mohanaki
mohanaki

Reputation: 258

How to log performance for each node in a route in camel in the correct order of invocation and not in the order of completion?

I have a simple route like this

    from("file:data/inbox?noop=true").transform().body().to("file:data/outbox").bean(UpdateInventory.class);
            from("direct:update").to("file:data/anotherbox").to("direct:newupdate");
            from("direct:newupdate").to("file:data/newbox");

And the output i am expecting is

   -file://data/inbox
  --transform[simple{body}]        15 ms
  --file:data/outbox                5
  ---bean[com.classico.sample.UpdateInventory@3a469fea   19
  ---file:data/anotherbox                                6
  ----direct:newupdate                                   5
  -----file:data/newbox                                    4

I tried using a EventNotifier and when the ExchangeCompletedEvent is received i fetched the message History.But since the second exchange is completed first message history is showing up in the reverse order of invocation.Is it possible to store all the messgae histories in a collection and print them in reverse order or Is there any event that is suitable for this.?

 if (event instanceof ExchangeCompletedEvent) { 
                    ExchangeCompletedEvent exchangeCompletedEvent = (ExchangeCompletedEvent) event; 
                    Exchange exchange = exchangeCompletedEvent.getExchange(); 
                    String routeId = exchange.getFromRouteId(); 
                    List<MessageHistory> list = exchange.getProperty(Exchange.MESSAGE_HISTORY, List.class); 

                    for (MessageHistory history : list) { 
                            String id = history.getNode().getId(); 
                            String label = URISupport.sanitizeUri(history.getNode().getLabel()); 

                            log.info(String.format(MESSAGE_HISTORY_OUTPUT, routeId, id, label, history.getElapsed())); 
                    }
}

Upvotes: 1

Views: 1813

Answers (2)

Claus Ibsen
Claus Ibsen

Reputation: 55525

You can use JMX to get all that details for each processor.

There is also a dumpRouteStatsAsXml operation on each route / camelContext that can output a xml file of the route(s) with all performance stats.

We use this in the hawtio web console to list this kind of information.

Also the Camel Karaf / Jolokia Commands uses this as well

And in next release of Camel you can also easier get the various processor mbeans, from CamelContext if you know their id, using

Then you can use the getters on the mbean to get the performance stats.

The event notifer which was suggested is also great, but the events are on a higher level, although you get an event for sending to an endpoint, such as to some external system, which often is enough to capture details about. For low level details as asked here, then you need to use the JMX stats.

Ohh I forgot to tell about the message history EIP which also has a trace of how the message was routed with time taken stats as well.

That is maybe also just what you need, then you can get that information from the exchange as shown on that link.

Upvotes: 2

nerdyoutdoorsman
nerdyoutdoorsman

Reputation: 134

I would suggest using the camel EventNotifier. You can find documentation on how to use it here:

http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html

Upvotes: 0

Related Questions