Reputation: 5850
I have two routes which execute some command every 2 seconds on different servers and print the output to the same file:
camelCtx.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("ssh://username:password@host1:port?delay=2&pollCommand=whoami")
.to("file:///tmp/?fileName=test.txt");
}
});
camelCtx.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("ssh://username:password@host2:port?delay=2&pollCommand=whoami")
.to("file:///tmp/?fileName=test.txt");
}
});
I would like to be sure that the two routes were started at the same time and also prefix output of each command with timestamp when route was started. For the second problem I tried custom process:
.process(exchange -> {
String body = exchange.getIn().getBody(String.class);
exchange.getIn().setBody(System.currentTimeMillis() + " " + body);
})
but it obviously gives the time when the output was received.
I also can execute date +%s%N
before executing the command, so that pollCommand
parameter would look like this:
...&pollCommand=date +%s%N;whoami"...
but in this case it's the time when connection to the server is already established, which is a bit too late...
So how to get the 'start time' of the route?
And also how to synchronise several routes so that they execute simultaneously?
Upvotes: 0
Views: 182
Reputation: 55525
If you mean the time that the exchange (camel message) on the route was started/created then you can access that information from the exchange property.
For example from a Camel Processor
you can do:
Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
You can use that information to build a file name which you can set with the header Exchange.FILE_NAME
when will then override the filename configured in the endpoint uri, so you can include the timestamp.
Upvotes: 1