Package org.apache.camel.builder
Class RouteBuilder
java.lang.Object
org.apache.camel.builder.BuilderSupport
org.apache.camel.builder.RouteBuilder
- All Implemented Interfaces:
org.apache.camel.CamelContextAware,org.apache.camel.Ordered,org.apache.camel.RoutesBuilder,org.apache.camel.spi.HasCamelContext,org.apache.camel.spi.ResourceAware
- Direct Known Subclasses:
AdviceWithRouteBuilder,RouteConfigurationBuilder
public abstract class RouteBuilder
extends BuilderSupport
implements org.apache.camel.RoutesBuilder, org.apache.camel.Ordered, org.apache.camel.spi.ResourceAware
-
Field Summary
FieldsFields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor) Adds the givenRouteBuilderLifecycleStrategyto be used.static voidaddRoutes(org.apache.camel.CamelContext context, LambdaRouteBuilder rbc) Add routes to a context using a lambda expression.voidaddRoutesToCamelContext(org.apache.camel.CamelContext context) voidaddTemplatedRoutesToCamelContext(org.apache.camel.CamelContext context) voidbindToRegistry(String id, Class<?> type, Object bean) Binds the bean to the repository (if possible).voidbindToRegistry(String id, Object bean) Binds the bean to the repository (if possible).protected voidvoidCalled on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.abstract voidCalled on initialization to build the routes using the fluent builder syntax.protected voidconfigureRest(RestDefinition rest) configureRests(org.apache.camel.CamelContext context) Configures the restsprotected voidconfigureRoute(RouteDefinition route) protected voidconfigureRouteConfiguration(RouteConfigurationDefinition routesConfiguration) configureRoutes(org.apache.camel.CamelContext context) Configures the routesprotected voidconfigureRouteTemplate(RouteTemplateDefinition routeTemplate) protected voidconfigureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute) A utility method allowing to build any data format using a fluent syntax as shown in the next example:voiderrorHandler(String ref) Installs the given error handler buildervoiderrorHandler(org.apache.camel.ErrorHandlerFactory errorHandlerFactory) Installs the given error handler builderA utility method allowing to build any language using a fluent syntax as shown in the next example:Creates a new route from the given URI inputfrom(EndpointConsumerBuilder endpointDefinition) from(org.apache.camel.Endpoint endpoint) Creates a new route from the given endpointCreates a new route from the given URI inputintgetOrder()Override this method to define ordering ofRouteBuilderclasses that are added to Camel from various runtimes such as camel-main, camel-spring-boot.org.apache.camel.spi.ResourceTheResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)protected voidinitializeCamelContext(org.apache.camel.CamelContext camelContext) Adds a route for an interceptor that intercepts every processing step.Adds a route for an interceptor that intercepts incoming messages on any inputs in this routeinterceptFrom(String uri) Adds a route for an interceptor that intercepts incoming messages on the given endpoint.Applies a route for an interceptor if an exchange is send to the given endpointstatic RouteBuilderloadRoutesBuilder(org.apache.camel.spi.Resource resource, org.apache.camel.util.function.ThrowingBiConsumer<Reader, RouteBuilder, Exception> consumer) static RouteBuilderloadRoutesBuilder(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder, Exception> consumer) LoadsRoutesBuilderusing the given consumer to create aRouteBuilderinstance.On completion callback for doing custom routing when theExchangeis complete.onException(Class<? extends Throwable> exception) Exception clause for catching certain exceptions and handling them.onException(Class<? extends Throwable>... exceptions) Exception clause for catching certain exceptions and handling them.protected voidprotected voidprotected voidprotected voidprotected voidprotected voidprotected voidRefers to the property placeholder<T> TpropertyInject(String key, Class<T> type) Injects a property placeholder value with the given key converted to the given type.voidremoveLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor) Adds the givenRouteBuilderLifecycleStrategy.rest()Creates a new REST serviceCreates a new REST serviceConfigures the REST servicesrouteTemplate(String id) Creates a new route templatevoidsetErrorHandlerFactory(org.apache.camel.ErrorHandlerFactory errorHandlerFactory) Sets the error handler to use with processors created by this buildervoidsetResource(org.apache.camel.spi.Resource resource) Sets theResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)voidsetRestCollection(RestsDefinition restCollection) voidsetRouteCollection(RoutesDefinition routeCollection) voidsetRouteTemplateCollection(RouteTemplatesDefinition routeTemplateCollection) voidsetTemplatedRouteCollection(TemplatedRoutesDefinition templatedRouteCollection) templatedRoute(String routeTemplateId) Creates a new templated routetoString()Create a newTransformerBuilder.updateRoutesToCamelContext(org.apache.camel.CamelContext context) Create a newValidatorBuilder.Methods inherited from class org.apache.camel.builder.BuilderSupport
body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, joor, joor, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, xpath, xpath, xpath, xpath
-
Field Details
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
RouteBuilder
public RouteBuilder() -
RouteBuilder
public RouteBuilder(org.apache.camel.CamelContext context)
-
-
Method Details
-
getResource
public org.apache.camel.spi.Resource getResource()TheResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
getResourcein interfaceorg.apache.camel.spi.ResourceAware
-
setResource
public void setResource(org.apache.camel.spi.Resource resource) Sets theResourcewhich is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
setResourcein interfaceorg.apache.camel.spi.ResourceAware
-
addRoutes
public static void addRoutes(org.apache.camel.CamelContext context, LambdaRouteBuilder rbc) throws Exception Add routes to a context using a lambda expression. It can be used as following:RouteBuilder.addRoutes(context, rb -> rb.from("direct:inbound").bean(MyBean.class)));- Parameters:
context- the camel context to add routesrbc- a lambda expression receiving theRouteBuilderto use to create routes- Throws:
Exception- if an error occurs
-
loadRoutesBuilder
public static RouteBuilder loadRoutesBuilder(org.apache.camel.spi.Resource resource, org.apache.camel.util.function.ThrowingBiConsumer<Reader, RouteBuilder, Exception> consumer) - Parameters:
resource- the resource to be loaded.consumer- the function used to create aRoutesBuilder- Returns:
- a
RoutesBuilder
-
loadRoutesBuilder
public static RouteBuilder loadRoutesBuilder(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder, Exception> consumer) LoadsRoutesBuilderusing the given consumer to create aRouteBuilderinstance.- Parameters:
consumer- the function used to create aRoutesBuilder- Returns:
- a
RoutesBuilder
-
getOrder
public int getOrder()Override this method to define ordering ofRouteBuilderclasses that are added to Camel from various runtimes such as camel-main, camel-spring-boot. This allows end users to control the ordering if some routes must be added and started before others. Use low numbers for higher priority. Normally the sorting will start from 0 and move upwards. So if you want to be last then useInteger.MAX_VALUEor egOrdered.LOWEST.- Specified by:
getOrderin interfaceorg.apache.camel.Ordered
-
toString
-
configure
Called on initialization to build the routes using the fluent builder syntax. This is a central method for RouteBuilder implementations to implement the routes using the Java fluent builder syntax.- Throws:
Exception- can be thrown during configuration
-
configuration
Called on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.- Throws:
Exception- can be thrown during configuration
-
bindToRegistry
Binds the bean to the repository (if possible).- Parameters:
id- the id of the beanbean- the bean
-
bindToRegistry
Binds the bean to the repository (if possible).- Parameters:
id- the id of the beantype- the type of the bean to associate the bindingbean- the bean
-
dataFormat
A utility method allowing to build any data format using a fluent syntax as shown in the next example:from("jms:queue:orders") .marshal( dataFormat() .swiftMt() .writeInJson(true) .end()) .to("file:data");- Returns:
- an entry point to the builder of all supported data formats.
-
expression
A utility method allowing to build any language using a fluent syntax as shown in the next example:from("file:data") .split( expression() .tokenize() .token("\n") .end()) .process("processEntry");- Returns:
- an entry point to the builder of all supported languages.
-
restConfiguration
Configures the REST services- Returns:
- the builder
-
routeTemplate
Creates a new route template- Returns:
- the builder
-
templatedRoute
Creates a new templated route- Returns:
- the builder
-
rest
Creates a new REST service- Returns:
- the builder
-
rest
Creates a new REST service- Parameters:
path- the base path- Returns:
- the builder
-
transformer
Create a newTransformerBuilder.- Returns:
- the builder
-
validator
Create a newValidatorBuilder.- Returns:
- the builder
-
from
Creates a new route from the given URI input- Parameters:
uri- the from uri- Returns:
- the builder
-
fromF
Creates a new route from the given URI input- Parameters:
uri- the String formatted from uriargs- arguments for the string formatting of the uri- Returns:
- the builder
-
from
Creates a new route from the given endpoint- Parameters:
endpoint- the from endpoint- Returns:
- the builder
-
from
-
errorHandler
public void errorHandler(org.apache.camel.ErrorHandlerFactory errorHandlerFactory) Installs the given error handler builder- Parameters:
errorHandlerFactory- the error handler to be used by default for all child routes
-
errorHandler
Installs the given error handler builder- Parameters:
ref- reference to the error handler to use
-
propertyInject
Injects a property placeholder value with the given key converted to the given type.- Parameters:
key- the property keytype- the type to convert the value as- Returns:
- the value, or null if value is empty
- Throws:
Exception- is thrown if property with key not found or error converting to the given type.
-
property
Refers to the property placeholder- Parameters:
key- the property key- Returns:
- the reference to the property using syntax {{key}}
-
intercept
Adds a route for an interceptor that intercepts every processing step.- Returns:
- the builder
-
interceptFrom
Adds a route for an interceptor that intercepts incoming messages on any inputs in this route- Returns:
- the builder
-
interceptFrom
Adds a route for an interceptor that intercepts incoming messages on the given endpoint.- Parameters:
uri- endpoint uri- Returns:
- the builder
-
interceptSendToEndpoint
Applies a route for an interceptor if an exchange is send to the given endpoint- Parameters:
uri- endpoint uri- Returns:
- the builder
-
onException
Exception clause for catching certain exceptions and handling them.- Parameters:
exception- exception to catch- Returns:
- the builder
-
onException
Exception clause for catching certain exceptions and handling them.- Parameters:
exceptions- list of exceptions to catch- Returns:
- the builder
-
onCompletion
On completion callback for doing custom routing when theExchangeis complete.- Returns:
- the builder
-
addRoutesToCamelContext
- Specified by:
addRoutesToCamelContextin interfaceorg.apache.camel.RoutesBuilder- Throws:
Exception
-
addTemplatedRoutesToCamelContext
public void addTemplatedRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception - Specified by:
addTemplatedRoutesToCamelContextin interfaceorg.apache.camel.RoutesBuilder- Throws:
Exception
-
updateRoutesToCamelContext
public Set<String> updateRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception - Specified by:
updateRoutesToCamelContextin interfaceorg.apache.camel.RoutesBuilder- Throws:
Exception
-
configureRoutes
Configures the routes- Parameters:
context- the Camel context- Returns:
- the routes configured
- Throws:
Exception- can be thrown during configuration
-
configureRests
Configures the rests- Parameters:
context- the Camel context- Returns:
- the rests configured
- Throws:
Exception- can be thrown during configuration
-
setErrorHandlerFactory
public void setErrorHandlerFactory(org.apache.camel.ErrorHandlerFactory errorHandlerFactory) Description copied from class:BuilderSupportSets the error handler to use with processors created by this builder- Overrides:
setErrorHandlerFactoryin classBuilderSupport
-
addLifecycleInterceptor
Adds the givenRouteBuilderLifecycleStrategyto be used. -
removeLifecycleInterceptor
Adds the givenRouteBuilderLifecycleStrategy. -
checkInitialized
- Throws:
Exception
-
initializeCamelContext
protected void initializeCamelContext(org.apache.camel.CamelContext camelContext) -
populateTemplatedRoutes
- Throws:
Exception
-
populateRouteTemplates
- Throws:
Exception
-
populateRoutes
- Throws:
Exception
-
populateOrUpdateRoutes
- Throws:
Exception
-
populateRests
- Throws:
Exception
-
populateTransformers
protected void populateTransformers() -
populateValidators
protected void populateValidators() -
getRestCollection
-
setRestCollection
-
getRestConfiguration
-
getRouteCollection
-
setRouteCollection
-
getRouteTemplateCollection
-
setRouteTemplateCollection
-
getTemplatedRouteCollection
-
setTemplatedRouteCollection
-
configureRest
-
configureRoute
-
configureRouteTemplate
-
configureTemplatedRoute
protected void configureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute) -
configureRouteConfiguration
-