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
Fields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLifecycleInterceptor
(RouteBuilderLifecycleStrategy interceptor) Adds the givenRouteBuilderLifecycleStrategy
to be used.static void
addRoutes
(org.apache.camel.CamelContext context, LambdaRouteBuilder rbc) Add routes to a context using a lambda expression.void
addRoutesToCamelContext
(org.apache.camel.CamelContext context) void
addTemplatedRoutesToCamelContext
(org.apache.camel.CamelContext context) void
bindToRegistry
(String id, Class<?> type, Object bean) Binds the bean to the repository (if possible).void
bindToRegistry
(String id, Object bean) Binds the bean to the repository (if possible).protected void
void
Called on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.abstract void
Called on initialization to build the routes using the fluent builder syntax.protected void
configureRest
(RestDefinition rest) configureRests
(org.apache.camel.CamelContext context) Configures the restsprotected void
configureRoute
(RouteDefinition route) protected void
configureRouteConfiguration
(RouteConfigurationDefinition routesConfiguration) configureRoutes
(org.apache.camel.CamelContext context) Configures the routesprotected void
configureRouteTemplate
(RouteTemplateDefinition routeTemplate) protected void
configureTemplatedRoute
(org.apache.camel.CamelContextAware templatedRoute) A utility method allowing to build any data format using a fluent syntax as shown in the next example:void
errorHandler
(String ref) Installs the given error handler buildervoid
errorHandler
(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 inputint
getOrder()
Override this method to define ordering ofRouteBuilder
classes that are added to Camel from various runtimes such as camel-main, camel-spring-boot.org.apache.camel.spi.Resource
TheResource
which is the source code for this route (such as XML, YAML, Groovy or Java source file)protected void
initializeCamelContext
(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 RouteBuilder
loadRoutesBuilder
(org.apache.camel.spi.Resource resource, org.apache.camel.util.function.ThrowingBiConsumer<Reader, RouteBuilder, Exception> consumer) static RouteBuilder
loadRoutesBuilder
(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder, Exception> consumer) LoadsRoutesBuilder
using the given consumer to create aRouteBuilder
instance.On completion callback for doing custom routing when theExchange
is 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 void
protected void
protected void
protected void
protected void
protected void
protected void
Refers to the property placeholder<T> T
propertyInject
(String key, Class<T> type) Injects a property placeholder value with the given key converted to the given type.void
removeLifecycleInterceptor
(RouteBuilderLifecycleStrategy interceptor) Adds the givenRouteBuilderLifecycleStrategy
.rest()
Creates a new REST serviceCreates a new REST serviceConfigures the REST servicesrouteTemplate
(String id) Creates a new route templatevoid
setErrorHandlerFactory
(org.apache.camel.ErrorHandlerFactory errorHandlerFactory) Sets the error handler to use with processors created by this buildervoid
setResource
(org.apache.camel.spi.Resource resource) Sets theResource
which is the source code for this route (such as XML, YAML, Groovy or Java source file)void
setRestCollection
(RestsDefinition restCollection) void
setRouteCollection
(RoutesDefinition routeCollection) void
setRouteTemplateCollection
(RouteTemplatesDefinition routeTemplateCollection) void
setTemplatedRouteCollection
(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()TheResource
which is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
getResource
in interfaceorg.apache.camel.spi.ResourceAware
-
setResource
public void setResource(org.apache.camel.spi.Resource resource) Sets theResource
which is the source code for this route (such as XML, YAML, Groovy or Java source file)- Specified by:
setResource
in 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 theRouteBuilder
to 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) LoadsRoutesBuilder
using the given consumer to create aRouteBuilder
instance.- Parameters:
consumer
- the function used to create aRoutesBuilder
- Returns:
- a
RoutesBuilder
-
getOrder
public int getOrder()Override this method to define ordering ofRouteBuilder
classes 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_VALUE
or egOrdered.LOWEST
.- Specified by:
getOrder
in 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 theExchange
is complete.- Returns:
- the builder
-
addRoutesToCamelContext
- Specified by:
addRoutesToCamelContext
in interfaceorg.apache.camel.RoutesBuilder
- Throws:
Exception
-
addTemplatedRoutesToCamelContext
public void addTemplatedRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception - Specified by:
addTemplatedRoutesToCamelContext
in interfaceorg.apache.camel.RoutesBuilder
- Throws:
Exception
-
updateRoutesToCamelContext
public Set<String> updateRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception - Specified by:
updateRoutesToCamelContext
in 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:BuilderSupport
Sets the error handler to use with processors created by this builder- Overrides:
setErrorHandlerFactory
in classBuilderSupport
-
addLifecycleInterceptor
Adds the givenRouteBuilderLifecycleStrategy
to 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
-