String lastEndpointUri = exchange.getProperty(Exchange.TO_ENDPOINT, String.class);
Exchange.TO_ENDPOINT have the constant value
This information is updated when Camel sends a message to any endpoint. So if it exists it's the last endpoint which Camel send the Exchange to.
When for example processing the Exchange at a given Endpoint and the message is to be moved into the dead letter queue, then Camel also decorates the Exchange with another property that contains that last endpoint:
String failedEndpointUri = exchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class);
Exchange.FAILURE_ENDPOINT have the constant value
This allows for example you to fetch this information in your dead letter queue and use that for error reporting. This is useable if the Camel route is a bit dynamic such as the dynamic Recipient List so you know which endpoints failed.
Notice: These information is kept on the Exchange even if the message was successfully processed by a given endpoint, and then later fails for example in a local Camel Component: Bean processing instead. So be aware that this is a hint that helps pinpoint errors.
from("activemq:queue:foo") .to("http://someserver/somepath") .beanRef("foo");
Now suppose the route above and a failure happens in the
foo bean. Then
Exchange.FAILURE_ENDPOINT will still
contain the value of
Starting with Camel 2.11, the route that failed can also be determined by using the following:
String failedRouteId = exchange.getProperty(Exchange.FAILURE_ROUTE_ID, String.class);