Class 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
    A Java DSL which is used to build Route instances in a CamelContext for smart routing.
    • Field Detail

      • log

        protected org.slf4j.Logger log
    • Constructor Detail

      • RouteBuilder

        public RouteBuilder()
      • RouteBuilder

        public RouteBuilder​(org.apache.camel.CamelContext context)
    • Method Detail

      • getResource

        public org.apache.camel.spi.Resource getResource()
        The Resource which is the source code for this route (such as XML, YAML, Groovy or Java source file)
        Specified by:
        getResource in interface org.apache.camel.spi.ResourceAware
      • setResource

        public void setResource​(org.apache.camel.spi.Resource resource)
        Sets the Resource which is the source code for this route (such as XML, YAML, Groovy or Java source file)
        Specified by:
        setResource in interface org.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 routes
        rbc - a lambda expression receiving the RouteBuilder 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)
        Loads RoutesBuilder from Resource using the given consumer to create a RouteBuilder instance.
        Parameters:
        resource - the resource to be loaded.
        consumer - the function used to create a RoutesBuilder
        Returns:
        a RoutesBuilder
      • loadRoutesBuilder

        public static RouteBuilder loadRoutesBuilder​(org.apache.camel.util.function.ThrowingConsumer<RouteBuilder,​Exception> consumer)
        Loads RoutesBuilder using the given consumer to create a RouteBuilder instance.
        Parameters:
        consumer - the function used to create a RoutesBuilder
        Returns:
        a RoutesBuilder
      • getOrder

        public int getOrder()
        Override this method to define ordering of RouteBuilder 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 use Integer.MAX_VALUE or eg Ordered.LOWEST.

        Specified by:
        getOrder in interface org.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 bean
        bean - 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 bean
        type - the type of the bean to associate the binding
        bean - the bean
      • 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 new TransformerBuilder.
        Returns:
        the builder
      • validator

        public ValidatorBuilder validator()
        Create a new ValidatorBuilder.
        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 uri
        args - 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
      • 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 key
        type - 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
      • addRoutesToCamelContext

        public void addRoutesToCamelContext​(org.apache.camel.CamelContext context)
                                     throws Exception
        Specified by:
        addRoutesToCamelContext in interface org.apache.camel.RoutesBuilder
        Throws:
        Exception
      • updateRoutesToCamelContext

        public Set<String> updateRoutesToCamelContext​(org.apache.camel.CamelContext context)
                                               throws Exception
        Specified by:
        updateRoutesToCamelContext in interface org.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 class BuilderSupport
      • populateTemplatedRoutes

        protected void populateTemplatedRoutes()
                                        throws Exception
        Throws:
        Exception
      • populateRouteTemplates

        protected void populateRouteTemplates()
                                       throws Exception
        Throws:
        Exception
      • populateOrUpdateRoutes

        protected void populateOrUpdateRoutes()
                                       throws Exception
        Throws:
        Exception
      • populateTransformers

        protected void populateTransformers()
      • populateValidators

        protected void populateValidators()
      • setRestCollection

        public void setRestCollection​(RestsDefinition restCollection)
      • setRouteCollection

        public void setRouteCollection​(RoutesDefinition routeCollection)
      • setRouteTemplateCollection

        public void setRouteTemplateCollection​(RouteTemplatesDefinition routeTemplateCollection)
      • setTemplatedRouteCollection

        public void setTemplatedRouteCollection​(TemplatedRoutesDefinition templatedRouteCollection)
      • configureRest

        protected void configureRest​(RestDefinition rest)
      • configureRoute

        protected void configureRoute​(RouteDefinition route)
      • configureTemplatedRoute

        protected void configureTemplatedRoute​(org.apache.camel.CamelContextAware templatedRoute)