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.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 Modifier and Type Field Description protected org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description RouteBuilder()
RouteBuilder(org.apache.camel.CamelContext context)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
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
checkInitialized()
void
configuration()
Called on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.abstract void
configure()
Called on initialization to build the routes using the fluent builder syntax.protected void
configureRest(RestDefinition rest)
RestsDefinition
configureRests(org.apache.camel.CamelContext context)
Configures the restsprotected void
configureRoute(RouteDefinition route)
protected void
configureRouteConfiguration(RouteConfigurationDefinition routesConfiguration)
RoutesDefinition
configureRoutes(org.apache.camel.CamelContext context)
Configures the routesprotected void
configureRouteTemplate(RouteTemplateDefinition routeTemplate)
protected void
configureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute)
DataFormatBuilderFactory
dataFormat()
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 builderLanguageBuilderFactory
expression()
A utility method allowing to build any language using a fluent syntax as shown in the next example:RouteDefinition
from(String uri)
Creates a new route from the given URI inputRouteDefinition
from(EndpointConsumerBuilder endpointDefinition)
RouteDefinition
from(org.apache.camel.Endpoint endpoint)
Creates a new route from the given endpointRouteDefinition
fromF(String uri, Object... args)
Creates 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
getResource()
TheResource
which is the source code for this route (such as XML, YAML, Groovy or Java source file)RestsDefinition
getRestCollection()
RestConfigurationDefinition
getRestConfiguration()
RoutesDefinition
getRouteCollection()
RouteTemplatesDefinition
getRouteTemplateCollection()
TemplatedRoutesDefinition
getTemplatedRouteCollection()
InterceptDefinition
intercept()
Adds a route for an interceptor that intercepts every processing step.InterceptFromDefinition
interceptFrom()
Adds a route for an interceptor that intercepts incoming messages on any inputs in this routeInterceptFromDefinition
interceptFrom(String uri)
Adds a route for an interceptor that intercepts incoming messages on the given endpoint.InterceptSendToEndpointDefinition
interceptSendToEndpoint(String uri)
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.OnCompletionDefinition
onCompletion()
On completion callback for doing custom routing when theExchange
is complete.OnExceptionDefinition
onException(Class<? extends Throwable> exception)
Exception clause for catching certain exceptions and handling them.OnExceptionDefinition
onException(Class<? extends Throwable>... exceptions)
Exception clause for catching certain exceptions and handling them.protected void
populateOrUpdateRoutes()
protected void
populateRests()
protected void
populateRoutes()
protected void
populateRouteTemplates()
protected void
populateTemplatedRoutes()
protected void
populateTransformers()
protected void
populateValidators()
String
property(String key)
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
.RestDefinition
rest()
Creates a new REST serviceRestDefinition
rest(String path)
Creates a new REST serviceRestConfigurationDefinition
restConfiguration()
Configures the REST servicesRouteTemplateDefinition
routeTemplate(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)
TemplatedRouteDefinition
templatedRoute(String routeTemplateId)
Creates a new templated routeString
toString()
TransformerBuilder
transformer()
Create a newTransformerBuilder
.Set<String>
updateRoutesToCamelContext(org.apache.camel.CamelContext context)
ValidatorBuilder
validator()
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, endpoints, endpoints, 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
-
-
-
-
Method Detail
-
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
-
configure
public abstract void configure() throws Exception
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
public void configuration() throws Exception
Called on initialization to build routes configuration (global routes configurations) using the fluent builder syntax.- Throws:
Exception
- can be thrown during configuration
-
bindToRegistry
public void bindToRegistry(String id, Object bean)
Binds the bean to the repository (if possible).- Parameters:
id
- the id of the beanbean
- the bean
-
bindToRegistry
public void bindToRegistry(String id, Class<?> type, Object bean)
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
public DataFormatBuilderFactory 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
public LanguageBuilderFactory 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
public RestConfigurationDefinition restConfiguration()
Configures the REST services- Returns:
- the builder
-
routeTemplate
public RouteTemplateDefinition routeTemplate(String id)
Creates a new route template- Returns:
- the builder
-
templatedRoute
public TemplatedRouteDefinition templatedRoute(String routeTemplateId)
Creates a new templated route- Returns:
- the builder
-
rest
public RestDefinition rest()
Creates a new REST service- Returns:
- the builder
-
rest
public RestDefinition rest(String path)
Creates a new REST service- Parameters:
path
- the base path- Returns:
- the builder
-
transformer
public TransformerBuilder transformer()
Create a newTransformerBuilder
.- Returns:
- the builder
-
validator
public ValidatorBuilder validator()
Create a newValidatorBuilder
.- Returns:
- the builder
-
from
public RouteDefinition from(String uri)
Creates a new route from the given URI input- Parameters:
uri
- the from uri- Returns:
- the builder
-
fromF
public RouteDefinition fromF(String uri, Object... args)
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
public RouteDefinition from(org.apache.camel.Endpoint endpoint)
Creates a new route from the given endpoint- Parameters:
endpoint
- the from endpoint- Returns:
- the builder
-
from
public RouteDefinition from(EndpointConsumerBuilder endpointDefinition)
-
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
public void errorHandler(String ref)
Installs the given error handler builder- Parameters:
ref
- reference to the error handler to use
-
propertyInject
public <T> T propertyInject(String key, Class<T> type) throws Exception
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
public String property(String key)
Refers to the property placeholder- Parameters:
key
- the property key- Returns:
- the reference to the property using syntax {{key}}
-
intercept
public InterceptDefinition intercept()
Adds a route for an interceptor that intercepts every processing step.- Returns:
- the builder
-
interceptFrom
public InterceptFromDefinition interceptFrom()
Adds a route for an interceptor that intercepts incoming messages on any inputs in this route- Returns:
- the builder
-
interceptFrom
public InterceptFromDefinition interceptFrom(String uri)
Adds a route for an interceptor that intercepts incoming messages on the given endpoint.- Parameters:
uri
- endpoint uri- Returns:
- the builder
-
interceptSendToEndpoint
public InterceptSendToEndpointDefinition interceptSendToEndpoint(String uri)
Applies a route for an interceptor if an exchange is send to the given endpoint- Parameters:
uri
- endpoint uri- Returns:
- the builder
-
onException
public OnExceptionDefinition onException(Class<? extends Throwable> exception)
Exception clause for catching certain exceptions and handling them.- Parameters:
exception
- exception to catch- Returns:
- the builder
-
onException
public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions)
Exception clause for catching certain exceptions and handling them.- Parameters:
exceptions
- list of exceptions to catch- Returns:
- the builder
-
onCompletion
public OnCompletionDefinition onCompletion()
On completion callback for doing custom routing when theExchange
is complete.- Returns:
- the builder
-
addRoutesToCamelContext
public void addRoutesToCamelContext(org.apache.camel.CamelContext context) throws Exception
- 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
public RoutesDefinition configureRoutes(org.apache.camel.CamelContext context) throws Exception
Configures the routes- Parameters:
context
- the Camel context- Returns:
- the routes configured
- Throws:
Exception
- can be thrown during configuration
-
configureRests
public RestsDefinition configureRests(org.apache.camel.CamelContext context) throws Exception
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
public void addLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)
Adds the givenRouteBuilderLifecycleStrategy
to be used.
-
removeLifecycleInterceptor
public void removeLifecycleInterceptor(RouteBuilderLifecycleStrategy interceptor)
Adds the givenRouteBuilderLifecycleStrategy
.
-
populateTransformers
protected void populateTransformers()
-
populateValidators
protected void populateValidators()
-
getRestCollection
public RestsDefinition getRestCollection()
-
setRestCollection
public void setRestCollection(RestsDefinition restCollection)
-
getRestConfiguration
public RestConfigurationDefinition getRestConfiguration()
-
getRouteCollection
public RoutesDefinition getRouteCollection()
-
setRouteCollection
public void setRouteCollection(RoutesDefinition routeCollection)
-
getRouteTemplateCollection
public RouteTemplatesDefinition getRouteTemplateCollection()
-
setRouteTemplateCollection
public void setRouteTemplateCollection(RouteTemplatesDefinition routeTemplateCollection)
-
getTemplatedRouteCollection
public TemplatedRoutesDefinition getTemplatedRouteCollection()
-
setTemplatedRouteCollection
public void setTemplatedRouteCollection(TemplatedRoutesDefinition templatedRouteCollection)
-
configureRest
protected void configureRest(RestDefinition rest)
-
configureRoute
protected void configureRoute(RouteDefinition route)
-
configureRouteTemplate
protected void configureRouteTemplate(RouteTemplateDefinition routeTemplate)
-
configureTemplatedRoute
protected void configureTemplatedRoute(org.apache.camel.CamelContextAware templatedRoute)
-
configureRouteConfiguration
protected void configureRouteConfiguration(RouteConfigurationDefinition routesConfiguration)
-
-