Package org.apache.camel.builder
Class AdviceWith
java.lang.Object
org.apache.camel.builder.AdviceWith
Use this for using the advice with feature.
Allows you to advice or enhance an existing route using a RouteBuilder style. For example you can add interceptors to
intercept sending outgoing messages to assert those messages are as expected.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RouteDefinition
adviceWith
(Object routeId, org.apache.camel.CamelContext camelContext, RouteBuilder builder) Advices this route with the route builder.static RouteDefinition
adviceWith
(org.apache.camel.CamelContext camelContext, Object routeId, boolean logXml, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) Advices this route with the route builder using a lambda expression.static RouteDefinition
adviceWith
(org.apache.camel.CamelContext camelContext, Object routeId, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) Advices this route with the route builder using a lambda expression.static RouteDefinition
adviceWith
(RouteDefinition definition, org.apache.camel.CamelContext camelContext, RouteBuilder builder) Advices this route with the route builder.
-
Method Details
-
adviceWith
public static RouteDefinition adviceWith(org.apache.camel.CamelContext camelContext, Object routeId, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) throws ExceptionAdvices this route with the route builder using a lambda expression. It can be used as following:AdviceWith.adviceWith(context, "myRoute", a -> a.weaveAddLast().to("mock:result"));
Important: It is recommended to only advice a given route once (you can of course advice multiple routes). If you do it multiple times, then it may not work as expected, especially when any kind of error handling is involved. The advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route. This is mostly used for testing purpose to add interceptors and the likes to an existing route. Will stop and remove the old route from camel context and add and start this new advised route.- Parameters:
camelContext
- the camel contextrouteId
- either the route id as a string value, or null to chose the 1st route, or you can specify a number for the n'th route, or provide the route definition instance directly as well.builder
- the advice with route builder- Returns:
- a new route which is this route merged with the route builder
- Throws:
Exception
- can be thrown from the route builder
-
adviceWith
public static RouteDefinition adviceWith(org.apache.camel.CamelContext camelContext, Object routeId, boolean logXml, org.apache.camel.util.function.ThrowingConsumer<AdviceWithRouteBuilder, Exception> builder) throws ExceptionAdvices this route with the route builder using a lambda expression. It can be used as following:AdviceWith.adviceWith(context, "myRoute", false, a -> a.weaveAddLast().to("mock:result"));
Important: It is recommended to only advice a given route once (you can of course advice multiple routes). If you do it multiple times, then it may not work as expected, especially when any kind of error handling is involved. The advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route. This is mostly used for testing purpose to add interceptors and the likes to an existing route. Will stop and remove the old route from camel context and add and start this new advised route.- Parameters:
camelContext
- the camel contextrouteId
- either the route id as a string value, or null to chose the 1st route, or you can specify a number for the n'th route, or provide the route definition instance directly as well.logXml
- whether to log the before and after advices routes as XML to the log (this can be turned off to perform faster)builder
- the advice with route builder- Returns:
- a new route which is this route merged with the route builder
- Throws:
Exception
- can be thrown from the route builder
-
adviceWith
public static RouteDefinition adviceWith(Object routeId, org.apache.camel.CamelContext camelContext, RouteBuilder builder) throws Exception Advices this route with the route builder. Important: It is recommended to only advice a given route once (you can of course advice multiple routes). If you do it multiple times, then it may not work as expected, especially when any kind of error handling is involved. The Camel team plan for Camel 3.0 to support this as internal refactorings in the routing engine is needed to support this properly. You can use a regularRouteBuilder
but the specializedAdviceWithRouteBuilder
has additional features when using the advice with feature. We therefore suggest you to use theAdviceWithRouteBuilder
. The advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route. This is mostly used for testing purpose to add interceptors and the likes to an existing route. Will stop and remove the old route from camel context and add and start this new advised route.- Parameters:
routeId
- either the route id as a string value, or null to chose the 1st route, or you can specify a number for the n'th route, or provide the route definition instance directly as well.camelContext
- the camel contextbuilder
- the route builder- Returns:
- a new route which is this route merged with the route builder
- Throws:
Exception
- can be thrown from the route builder- See Also:
-
adviceWith
public static RouteDefinition adviceWith(RouteDefinition definition, org.apache.camel.CamelContext camelContext, RouteBuilder builder) throws Exception Advices this route with the route builder. Important: It is recommended to only advice a given route once (you can of course advice multiple routes). If you do it multiple times, then it may not work as expected, especially when any kind of error handling is involved. The Camel team plan for Camel 3.0 to support this as internal refactorings in the routing engine is needed to support this properly. You can use a regularRouteBuilder
but the specializedAdviceWithRouteBuilder
has additional features when using the advice with feature. We therefore suggest you to use theAdviceWithRouteBuilder
. The advice process will add the interceptors, on exceptions, on completions etc. configured from the route builder to this route. This is mostly used for testing purpose to add interceptors and the likes to an existing route. Will stop and remove the old route from camel context and add and start this new advised route.- Parameters:
definition
- the model definitioncamelContext
- the camel contextbuilder
- the route builder- Returns:
- a new route which is this route merged with the route builder
- Throws:
Exception
- can be thrown from the route builder- See Also:
-