Interface CamelContext

All Superinterfaces:
AutoCloseable, CamelContextLifecycle, RuntimeConfiguration
All Known Subinterfaces:
CatalogCamelContext

public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguration
Interface used to represent the CamelContext used to configure routes and the policies to use during message exchanges between endpoints.

The CamelContext offers the following methods CamelContextLifecycle to control the lifecycle:

Notice: CamelContextLifecycle.stop() and CamelContextLifecycle.suspend() will gracefully stop/suspend routes ensuring any messages in progress will be given time to complete. See more details at ShutdownStrategy.

If you are doing a hot restart then it's advised to use the suspend/resume methods which ensure a faster restart but also allows any internal state to be kept as is. The stop/start approach will do a cold restart of Camel, where all internal state is reset.

End users are advised to use suspend/resume. Using stop is for shutting down Camel and it's not guaranteed that when it's being started again using the start method that Camel will operate consistently.

You can use the getCamelContextExtension() to obtain the extension point for the CamelContext. This extension point exposes internal APIs via ExtendedCamelContext.

  • Method Details

    • getCamelContextExtension

      ExtendedCamelContext getCamelContextExtension()
      Gets the ExtendedCamelContext that contains the extension points for internal context APIs. These APIs are intended for internal usage within Camel and end-users should avoid using them.
      Returns:
      this ExtendedCamelContext extension point for this context.
    • isVetoStarted

      boolean isVetoStarted()
      If CamelContext during the start procedure was vetoed, and therefore causing Camel to not start.
    • getName

      String getName()
      Gets the name (id) of this CamelContext.
      Returns:
      the name
    • getDescription

      String getDescription()
      Gets the description of this CamelContext.
      Returns:
      the description, or null if no description has been set.
    • getNameStrategy

      CamelContextNameStrategy getNameStrategy()
      Gets the current name strategy
      Returns:
      name strategy
    • setNameStrategy

      void setNameStrategy(CamelContextNameStrategy nameStrategy)
      Sets a custom name strategy
      Parameters:
      nameStrategy - name strategy
    • getManagementNameStrategy

      ManagementNameStrategy getManagementNameStrategy()
      Gets the current management name strategy
      Returns:
      management name strategy
    • setManagementNameStrategy

      void setManagementNameStrategy(ManagementNameStrategy nameStrategy)
      Sets a custom management name strategy
      Parameters:
      nameStrategy - name strategy
    • getManagementName

      String getManagementName()
      Gets the name this CamelContext was registered in JMX.

      The reason that a CamelContext can have a different name in JMX is the fact to remedy for name clash in JMX when having multiple CamelContexts in the same JVM. Camel will automatic reassign and use a free name to avoid failing to start.

      Returns:
      the management name
    • setManagementName

      void setManagementName(String name)
      Sets the name this CamelContext will be registered in JMX.
    • getVersion

      String getVersion()
      Gets the version of the this CamelContext.
      Returns:
      the version
    • getUptime

      String getUptime()
      Gets the uptime in a human readable format
      Returns:
      the uptime in days/hours/minutes
    • getUptimeMillis

      long getUptimeMillis()
      Gets the uptime in milli seconds
      Returns:
      the uptime in millis seconds
    • getStartDate

      Date getStartDate()
      Gets the date and time Camel was started up.
    • addService

      void addService(Object object) throws Exception
      Adds a service to this CamelContext, which allows this CamelContext to control the lifecycle, ensuring the service is stopped when the CamelContext stops.

      The service will also have CamelContext injected if its CamelContextAware. The service will also be enlisted in JMX for management (if JMX is enabled). The service will be started, if its not already started.

      Parameters:
      object - the service
      Throws:
      Exception - can be thrown when starting the service
    • addService

      void addService(Object object, boolean stopOnShutdown) throws Exception
      Adds a service to this CamelContext.

      The service will also have CamelContext injected if its CamelContextAware. The service will also be enlisted in JMX for management (if JMX is enabled). The service will be started, if its not already started.

      If the option closeOnShutdown is true then this CamelContext will control the lifecycle, ensuring the service is stopped when the CamelContext stops. If the option closeOnShutdown is false then this CamelContext will not stop the service when the CamelContext stops.

      Parameters:
      object - the service
      stopOnShutdown - whether to stop the service when this CamelContext shutdown.
      Throws:
      Exception - can be thrown when starting the service
    • addService

      void addService(Object object, boolean stopOnShutdown, boolean forceStart) throws Exception
      Adds a service to this CamelContext.

      The service will also have CamelContext injected if its CamelContextAware. The service will also be enlisted in JMX for management (if JMX is enabled). The service will be started, if its not already started.

      If the option closeOnShutdown is true then this CamelContext will control the lifecycle, ensuring the service is stopped when the CamelContext stops. If the option closeOnShutdown is false then this CamelContext will not stop the service when the CamelContext stops.

      Parameters:
      object - the service
      stopOnShutdown - whether to stop the service when this CamelContext shutdown.
      forceStart - whether to force starting the service right now, as otherwise the service may be deferred being started to later using deferStartService(Object, boolean)
      Throws:
      Exception - can be thrown when starting the service
    • addPrototypeService

      void addPrototypeService(Object object) throws Exception
      Adds a service to this CamelContext (prototype scope).

      The service will also have CamelContext injected if its CamelContextAware. The service will be started, if its not already started.

      Parameters:
      object - the service
      Throws:
      Exception - can be thrown when starting the service
    • removeService

      boolean removeService(Object object) throws Exception
      Removes a service from this CamelContext.

      The service is assumed to have been previously added using addService(Object) method. This method will not change the service lifecycle.

      Parameters:
      object - the service
      Returns:
      true if the service was removed, false if no service existed
      Throws:
      Exception - can be thrown if error removing the service
    • hasService

      boolean hasService(Object object)
      Has the given service already been added to this CamelContext?
      Parameters:
      object - the service
      Returns:
      true if already added, false if not.
    • hasService

      <T> T hasService(Class<T> type)
      Has the given service type already been added to this CamelContext?
      Parameters:
      type - the class type
      Returns:
      the service instance or null if not already added.
    • hasServices

      <T> Set<T> hasServices(Class<T> type)
      Has the given service type already been added to this CamelContext?
      Parameters:
      type - the class type
      Returns:
      the services instance or empty set.
    • deferStartService

      void deferStartService(Object object, boolean stopOnShutdown) throws Exception
      Defers starting the service until CamelContext is (almost started) or started and has initialized all its prior services and routes.

      If CamelContext is already started then the service is started immediately.

      Parameters:
      object - the service
      stopOnShutdown - whether to stop the service when this CamelContext shutdown. Setting this to true will keep a reference to the service in this CamelContext until the CamelContext is stopped. So do not use it for short lived services.
      Throws:
      Exception - can be thrown when starting the service, which is only attempted if CamelContext has already been started when calling this method.
    • addStartupListener

      void addStartupListener(StartupListener listener) throws Exception
      Adds the given listener to be invoked when CamelContext have just been started.

      This allows listeners to do any custom work after the routes and other services have been started and are running.

      Important: The listener will always be invoked, also if the CamelContext has already been started, see the StartupListener.onCamelContextStarted(CamelContext, boolean) method.

      Parameters:
      listener - the listener
      Throws:
      Exception - can be thrown if CamelContext is already started and the listener is invoked and cause an exception to be thrown
    • addComponent

      void addComponent(String componentName, Component component)
      Adds a component to the context. Notice the component will be auto-started if Camel is already started.
      Parameters:
      componentName - the name the component is registered as
      component - the component
    • hasComponent

      Component hasComponent(String componentName)
      Is the given component already registered?
      Parameters:
      componentName - the name of the component
      Returns:
      the registered Component or null if not registered
    • getComponent

      Component getComponent(String componentName)
      Gets a component from the CamelContext by name.

      Notice the returned component will be auto-started. If you do not intend to do that then use getComponent(String, boolean, boolean).

      Parameters:
      componentName - the name of the component
      Returns:
      the component
    • getComponent

      Component getComponent(String name, boolean autoCreateComponents)
      Gets a component from the CamelContext by name.

      Notice the returned component will be auto-started. If you do not intend to do that then use getComponent(String, boolean, boolean).

      Parameters:
      name - the name of the component
      autoCreateComponents - whether or not the component should be lazily created if it does not already exist
      Returns:
      the component
    • getComponent

      Component getComponent(String name, boolean autoCreateComponents, boolean autoStart)
      Gets a component from the CamelContext by name.
      Parameters:
      name - the name of the component
      autoCreateComponents - whether or not the component should be lazily created if it does not already exist
      autoStart - whether to auto start the component if CamelContext is already started.
      Returns:
      the component
    • getComponent

      <T extends Component> T getComponent(String name, Class<T> componentType)
      Gets a component from the CamelContext by name and specifying the expected type of component.
      Parameters:
      name - the name to lookup
      componentType - the expected type
      Returns:
      the component
    • getComponentNames

      Set<String> getComponentNames()
      Gets a readonly list of names of the components currently registered
      Returns:
      a readonly list with the names of the components
    • removeComponent

      Component removeComponent(String componentName)
      Removes a previously added component.

      The component being removed will be stopped first.

      Parameters:
      componentName - the component name to remove
      Returns:
      the previously added component or null if it had not been previously added.
    • getEndpointRegistry

      EndpointRegistry<? extends ValueHolder<String>> getEndpointRegistry()
    • getEndpoint

      Endpoint getEndpoint(String uri)
      Resolves the given name to an Endpoint of the specified type. If the name has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and registered in the EndpointRegistry.
      Parameters:
      uri - the URI of the endpoint
      Returns:
      the endpoint
    • getEndpoint

      Endpoint getEndpoint(String uri, Map<String,Object> parameters)
      Resolves the given name to an Endpoint of the specified type. If the name has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and registered in the EndpointRegistry.
      Parameters:
      uri - the URI of the endpoint
      parameters - the parameters to customize the endpoint
      Returns:
      the endpoint
    • getEndpoint

      <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType)
      Resolves the given name to an Endpoint of the specified type. If the name has a singleton endpoint registered, then the singleton is returned. Otherwise, a new Endpoint is created and registered in the EndpointRegistry.
      Parameters:
      name - the name of the endpoint
      endpointType - the expected type
      Returns:
      the endpoint
    • getEndpoints

      Collection<Endpoint> getEndpoints()
      Returns a read-only Collection of all of the endpoints from the EndpointRegistry
      Returns:
      all endpoints
    • hasEndpoint

      Endpoint hasEndpoint(String uri)
      Is the given endpoint already registered in the EndpointRegistry
      Parameters:
      uri - the URI of the endpoint
      Returns:
      the registered endpoint or null if not registered
    • addEndpoint

      Endpoint addEndpoint(String uri, Endpoint endpoint) throws Exception
      Adds and starts the endpoint to the EndpointRegistry using the given URI.
      Parameters:
      uri - the URI to be used to resolve this endpoint
      endpoint - the endpoint to be started and added to the registry
      Returns:
      the old endpoint that was previously registered or null if none was registered
      Throws:
      Exception - if the new endpoint could not be started or the old endpoint could not be stopped
    • removeEndpoint

      void removeEndpoint(Endpoint endpoint) throws Exception
      Removes the endpoint from the EndpointRegistry.

      The endpoint being removed will be stopped first.

      Parameters:
      endpoint - the endpoint
      Throws:
      Exception - if the endpoint could not be stopped
    • removeEndpoints

      Collection<Endpoint> removeEndpoints(String pattern) throws Exception
      Removes all endpoints with the given URI from the EndpointRegistry.

      The endpoints being removed will be stopped first.

      Parameters:
      pattern - an uri or pattern to match
      Returns:
      a collection of endpoints removed which could be empty if there are no endpoints found for the given pattern
      Throws:
      Exception - if at least one endpoint could not be stopped
      See Also:
      • for pattern
    • getGlobalEndpointConfiguration

      GlobalEndpointConfiguration getGlobalEndpointConfiguration()
      Gets the global endpoint configuration, where you can configure common endpoint options.
    • setRouteController

      void setRouteController(RouteController routeController)
      Sets a custom RouteController to use
      Parameters:
      routeController - the route controller
    • getRouteController

      RouteController getRouteController()
      Returns:
      the route controller.
    • getRoutes

      List<Route> getRoutes()
      Returns the current routes in this CamelContext
      Returns:
      the current routes
    • getRoutesSize

      int getRoutesSize()
      Returns the total number of routes in this CamelContext
    • getRoute

      Route getRoute(String id)
      Gets the route with the given id
      Parameters:
      id - id of the route
      Returns:
      the route or null if not found
    • getProcessor

      Processor getProcessor(String id)
      Gets the processor from any of the routes which with the given id
      Parameters:
      id - id of the processor
      Returns:
      the processor or null if not found
    • getProcessor

      <T extends Processor> T getProcessor(String id, Class<T> type)
      Gets the processor from any of the routes which with the given id
      Parameters:
      id - id of the processor
      type - the processor type
      Returns:
      the processor or null if not found
      Throws:
      ClassCastException - is thrown if the type is not correct type
    • addRoutes

      void addRoutes(RoutesBuilder builder) throws Exception
      Adds a collection of routes to this CamelContext using the given builder to build them.

      Important: The added routes will only be started, if CamelContext is already started. You may want to check the state of CamelContext before adding the routes, using the CamelContextLifecycle.getStatus() method.

      Important: Each route in the same CamelContext must have an unique route id. If you use the API from CamelContext or org.apache.camel.model.ModelCamelContext to add routes, then any new routes which has a route id that matches an old route, then the old route is replaced by the new route.

      Parameters:
      builder - the builder which will create the routes and add them to this CamelContext
      Throws:
      Exception - if the routes could not be created for whatever reason
    • addTemplatedRoutes

      void addTemplatedRoutes(RoutesBuilder builder) throws Exception
      Adds the templated routes from the routes builder. For example in Java DSL you can use org.apache.camel.builder.TemplatedRouteBuilder.
      Parameters:
      builder - the builder which has templated routes
      Throws:
      Exception - if the routes could not be created for whatever reason
    • addRoutesConfigurations

      void addRoutesConfigurations(RouteConfigurationsBuilder builder) throws Exception
      Adds the routes configurations (global configuration for all routes) from the routes builder.
      Parameters:
      builder - the builder which has routes configurations
      Throws:
      Exception - if the routes configurations could not be created for whatever reason
    • removeRoute

      boolean removeRoute(String routeId) throws Exception
      Removes the given route (the route must be stopped before it can be removed).

      A route which is removed will be unregistered from JMX, have its services stopped/shutdown and the route definition etc. will also be removed. All the resources related to the route will be stopped and cleared.

      Important: When removing a route, the Endpoints which are in the static cache of EndpointRegistry and are only used by the route (not used by other routes) will also be removed. But Endpoints which may have been created as part of routing messages by the route, and those endpoints are enlisted in the dynamic cache of EndpointRegistry are not removed. To remove those dynamic kind of endpoints, use the removeEndpoints(String) method. If not removing those endpoints, they will be kept in the dynamic cache of EndpointRegistry, but my eventually be removed (evicted) when they have not been in use for a longer period of time; and the dynamic cache upper limit is hit, and it evicts the least used endpoints.

      End users can use this method to remove unwanted routes or temporary routes which no longer is in demand.

      Parameters:
      routeId - the route id
      Returns:
      true if the route was removed, false if the route could not be removed because it's not stopped
      Throws:
      Exception - is thrown if the route could not be shutdown for whatever reason
    • addRouteFromTemplate

      String addRouteFromTemplate(String routeId, String routeTemplateId, Map<String,Object> parameters) throws Exception
      Adds a new route from a given route template. Camel end users should favour using org.apache.camel.builder.TemplatedRouteBuilder which is a fluent builder with more functionality than this API.
      Parameters:
      routeId - the id of the new route to add (optional)
      routeTemplateId - the id of the route template (mandatory)
      parameters - parameters to use for the route template when creating the new route
      Returns:
      the id of the route added (for example when an id was auto assigned)
      Throws:
      Exception - is thrown if error creating and adding the new route
    • addRouteFromTemplate

      String addRouteFromTemplate(String routeId, String routeTemplateId, String prefixId, Map<String,Object> parameters) throws Exception
      Adds a new route from a given route template. Camel end users should favour using org.apache.camel.builder.TemplatedRouteBuilder which is a fluent builder with more functionality than this API.
      Parameters:
      routeId - the id of the new route to add (optional)
      routeTemplateId - the id of the route template (mandatory)
      prefixId - prefix to use for all node ids (not route id). Use null for no prefix. (optional)
      parameters - parameters to use for the route template when creating the new route
      Returns:
      the id of the route added (for example when an id was auto assigned)
      Throws:
      Exception - is thrown if error creating and adding the new route
    • addRouteFromTemplate

      String addRouteFromTemplate(String routeId, String routeTemplateId, String prefixId, RouteTemplateContext routeTemplateContext) throws Exception
      Adds a new route from a given route template. Camel end users should favour using org.apache.camel.builder.TemplatedRouteBuilder which is a fluent builder with more functionality than this API.
      Parameters:
      routeId - the id of the new route to add (optional)
      routeTemplateId - the id of the route template (mandatory)
      prefixId - prefix to use for all node ids (not route id). Use null for no prefix. (optional)
      routeTemplateContext - the route template context (mandatory)
      Returns:
      the id of the route added (for example when an id was auto assigned)
      Throws:
      Exception - is thrown if error creating and adding the new route
    • removeRouteTemplates

      void removeRouteTemplates(String pattern) throws Exception
      Removes the route templates matching the pattern
      Parameters:
      pattern - pattern, such as * for all, or foo* to remove all foo templates
      Throws:
      Exception - is thrown if error during removing route templates
    • addRoutePolicyFactory

      void addRoutePolicyFactory(RoutePolicyFactory routePolicyFactory)
      Adds the given route policy factory
      Parameters:
      routePolicyFactory - the factory
    • getRoutePolicyFactories

      List<RoutePolicyFactory> getRoutePolicyFactories()
      Gets the route policy factories
      Returns:
      the list of current route policy factories
    • setRestConfiguration

      void setRestConfiguration(RestConfiguration restConfiguration)
      Sets a custom RestConfiguration
      Parameters:
      restConfiguration - the REST configuration
    • getRestConfiguration

      RestConfiguration getRestConfiguration()
      Gets the default REST configuration
      Returns:
      the configuration, or null if none has been configured.
    • setVaultConfiguration

      void setVaultConfiguration(VaultConfiguration vaultConfiguration)
      Sets a custom VaultConfiguration
      Parameters:
      vaultConfiguration - the vault configuration
    • getVaultConfiguration

      VaultConfiguration getVaultConfiguration()
      Gets the vault configuration
      Returns:
      the configuration, or null if none has been configured.
    • getRestRegistry

      RestRegistry getRestRegistry()
      Gets the RestRegistry to use
    • setRestRegistry

      void setRestRegistry(RestRegistry restRegistry)
      Sets a custom RestRegistry to use.
    • getTypeConverter

      TypeConverter getTypeConverter()
      Returns the type converter used to coerce types from one type to another.

      Notice that this CamelContext should be at least initialized before you can get the type converter.

      Returns:
      the converter
    • getTypeConverterRegistry

      TypeConverterRegistry getTypeConverterRegistry()
      Returns the type converter registry where type converters can be added or looked up
      Returns:
      the type converter registry
    • setTypeConverterRegistry

      void setTypeConverterRegistry(TypeConverterRegistry typeConverterRegistry)
      Configures the type converter registry to use, where type converters can be added or looked up.
      Parameters:
      typeConverterRegistry - the registry to use
    • getRegistry

      Registry getRegistry()
      Returns the registry used to lookup components by name and type such as SimpleRegistry, Spring ApplicationContext, JNDI, or the OSGi Service Registry.
      Returns:
      the registry
    • getRegistry

      <T> T getRegistry(Class<T> type)
      Returns the registry used to lookup components by name and as the given type
      Parameters:
      type - the registry type such as org.apache.camel.impl.JndiRegistry
      Returns:
      the registry, or null if the given type was not found as a registry implementation
    • getInjector

      Injector getInjector()
      Returns the injector used to instantiate objects by type
      Returns:
      the injector
    • setInjector

      void setInjector(Injector injector)
      Sets the injector to use
    • getLifecycleStrategies

      List<LifecycleStrategy> getLifecycleStrategies()
      Returns the lifecycle strategies used to handle lifecycle notifications
      Returns:
      the lifecycle strategies
    • addLifecycleStrategy

      void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy)
      Adds the given lifecycle strategy to be used.
      Parameters:
      lifecycleStrategy - the strategy
    • resolveLanguage

      Language resolveLanguage(String language) throws NoSuchLanguageException
      Resolves a language for creating expressions
      Parameters:
      language - name of the language
      Returns:
      the resolved language
      Throws:
      NoSuchLanguageException - is thrown if language could not be resolved
    • resolvePropertyPlaceholders

      String resolvePropertyPlaceholders(String text)
      Parses the given text and resolve any property placeholders - using {{key}}.

      Important: If resolving placeholders on an endpoint uri, then you SHOULD use EndpointHelper#resolveEndpointUriPropertyPlaceholders instead.

      Parameters:
      text - the text such as an endpoint uri or the likes
      Returns:
      the text with resolved property placeholders
      Throws:
      IllegalArgumentException - is thrown if property placeholders was used and there was an error resolving them
    • getPropertiesComponent

      PropertiesComponent getPropertiesComponent()
      Returns the configured properties component or create one if none has been configured.
      Returns:
      the properties component
    • setPropertiesComponent

      void setPropertiesComponent(PropertiesComponent propertiesComponent)
      Sets a custom properties component to be used.
    • getLanguageNames

      Set<String> getLanguageNames()
      Gets a readonly list with the names of the languages currently registered.
      Returns:
      a readonly list with the names of the languages
    • createProducerTemplate

      ProducerTemplate createProducerTemplate()
      Creates a new ProducerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate?

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Will use cache size defined in Camel property with key Exchange.MAXIMUM_CACHE_POOL_SIZE. If no key was defined then it will fallback to a default size of 1000. You can also use the ProducerTemplate.setMaximumCacheSize(int) method to use a custom value before starting the template.

      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • createProducerTemplate

      ProducerTemplate createProducerTemplate(int maximumCacheSize)
      Creates a new ProducerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate?

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Parameters:
      maximumCacheSize - the maximum cache size
      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • createFluentProducerTemplate

      FluentProducerTemplate createFluentProducerTemplate()
      Creates a new FluentProducerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate?

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Will use cache size defined in Camel property with key Exchange.MAXIMUM_CACHE_POOL_SIZE. If no key was defined then it will fallback to a default size of 1000. You can also use the FluentProducerTemplate.setMaximumCacheSize(int) method to use a custom value before starting the template.

      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • createFluentProducerTemplate

      FluentProducerTemplate createFluentProducerTemplate(int maximumCacheSize)
      Creates a new FluentProducerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate?

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Parameters:
      maximumCacheSize - the maximum cache size
      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • createConsumerTemplate

      ConsumerTemplate createConsumerTemplate()
      Creates a new ConsumerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate? as it also applies for ConsumerTemplate.

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Will use cache size defined in Camel property with key Exchange.MAXIMUM_CACHE_POOL_SIZE. If no key was defined then it will fallback to a default size of 1000. You can also use the ConsumerTemplate.setMaximumCacheSize(int) method to use a custom value before starting the template.

      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • createConsumerTemplate

      ConsumerTemplate createConsumerTemplate(int maximumCacheSize)
      Creates a new ConsumerTemplate which is started and therefore ready to use right away.

      See this FAQ before use: Why does Camel use too many threads with ProducerTemplate? as it also applies for ConsumerTemplate.

      Important: Make sure to call Service.stop() when you are done using the template, to clean up any resources.

      Parameters:
      maximumCacheSize - the maximum cache size
      Returns:
      the template
      Throws:
      RuntimeCamelException - is thrown if error starting the template
    • resolveDataFormat

      DataFormat resolveDataFormat(String name)
      Resolve an existing data format, or creates a new by the given its name
      Parameters:
      name - the data format name or a reference to it in the Registry
      Returns:
      the resolved data format, or null if not found
    • createDataFormat

      DataFormat createDataFormat(String name)
      Creates a new instance of the given data format given its name.
      Parameters:
      name - the data format name or a reference to a data format factory in the Registry
      Returns:
      the created data format, or null if not found
    • getDataFormatNames

      Set<String> getDataFormatNames()
      Gets a readonly list of names of the data formats currently registered
      Returns:
      a readonly list with the names of the data formats
    • resolveTransformer

      Transformer resolveTransformer(String name)
      Resolve a transformer given a scheme
      Parameters:
      name - the transformer name, usually a combination of some scheme and name.
      Returns:
      the resolved transformer, or null if not found
    • resolveTransformer

      Transformer resolveTransformer(DataType from, DataType to)
      Resolve a transformer given from/to data type.
      Parameters:
      from - from data type
      to - to data type
      Returns:
      the resolved transformer, or null if not found
    • getTransformerRegistry

      TransformerRegistry getTransformerRegistry()
      Returns:
      the TransformerRegistry
    • resolveValidator

      Validator resolveValidator(DataType type)
      Resolve a validator given from/to data type.
      Parameters:
      type - the data type
      Returns:
      the resolved validator, or null if not found
    • getValidatorRegistry

      ValidatorRegistry getValidatorRegistry()
      Returns:
      the ValidatorRegistry
    • setGlobalOptions

      void setGlobalOptions(Map<String,String> globalOptions)
      Sets global options that can be referenced in the camel context

      Important: This has nothing to do with property placeholders, and is just a plain set of key/value pairs which are used to configure global options on CamelContext, such as a maximum debug logging length etc. For property placeholders use resolvePropertyPlaceholders(String) method and see more details at the property placeholder documentation.

      Parameters:
      globalOptions - global options that can be referenced in the camel context
    • getGlobalOptions

      Map<String,String> getGlobalOptions()
      Gets global options that can be referenced in the camel context.

      Important: This has nothing to do with property placeholders, and is just a plain set of key/value pairs which are used to configure global options on CamelContext, such as a maximum debug logging length etc. For property placeholders use resolvePropertyPlaceholders(String) method and see more details at the property placeholder documentation.

      Returns:
      global options for this context
    • getGlobalOption

      String getGlobalOption(String key)
      Gets the global option value that can be referenced in the camel context

      Important: This has nothing to do with property placeholders, and is just a plain set of key/value pairs which are used to configure global options on CamelContext, such as a maximum debug logging length etc. For property placeholders use resolvePropertyPlaceholders(String) method and see more details at the property placeholder documentation.

      Returns:
      the string value of the global option
    • getClassResolver

      ClassResolver getClassResolver()
      Returns the class resolver to be used for loading/lookup of classes.
      Returns:
      the resolver
    • setClassResolver

      void setClassResolver(ClassResolver resolver)
      Sets the class resolver to be use
      Parameters:
      resolver - the resolver
    • getManagementStrategy

      ManagementStrategy getManagementStrategy()
      Gets the management strategy
      Returns:
      the management strategy
    • setManagementStrategy

      void setManagementStrategy(ManagementStrategy strategy)
      Sets the management strategy to use
      Parameters:
      strategy - the management strategy
    • disableJMX

      void disableJMX() throws IllegalStateException
      Disables using JMX as ManagementStrategy.

      Important: This method must be called before the CamelContext is started.

      Throws:
      IllegalStateException - is thrown if the CamelContext is not in stopped state.
    • getInflightRepository

      InflightRepository getInflightRepository()
      Gets the inflight repository
      Returns:
      the repository
    • setInflightRepository

      void setInflightRepository(InflightRepository repository)
      Sets a custom inflight repository to use
      Parameters:
      repository - the repository
    • getApplicationContextClassLoader

      ClassLoader getApplicationContextClassLoader()
      Gets the application CamelContext class loader which may be helpful for running camel in other containers
      Returns:
      the application CamelContext class loader
    • setApplicationContextClassLoader

      void setApplicationContextClassLoader(ClassLoader classLoader)
      Sets the application CamelContext class loader
      Parameters:
      classLoader - the class loader
    • getShutdownStrategy

      ShutdownStrategy getShutdownStrategy()
      Gets the current shutdown strategy.

      The shutdown strategy is not intended for Camel end users to use for stopping routes. Instead use RouteController via CamelContext.

      Returns:
      the strategy
    • setShutdownStrategy

      void setShutdownStrategy(ShutdownStrategy shutdownStrategy)
      Sets a custom shutdown strategy
      Parameters:
      shutdownStrategy - the custom strategy
    • getExecutorServiceManager

      ExecutorServiceManager getExecutorServiceManager()
      Gets the current ExecutorServiceManager
      Returns:
      the manager
    • setExecutorServiceManager

      void setExecutorServiceManager(ExecutorServiceManager executorServiceManager)
      Parameters:
      executorServiceManager - the custom manager
    • getMessageHistoryFactory

      MessageHistoryFactory getMessageHistoryFactory()
      Gets the current MessageHistoryFactory
      Returns:
      the factory
    • setMessageHistoryFactory

      void setMessageHistoryFactory(MessageHistoryFactory messageHistoryFactory)
      Sets a custom MessageHistoryFactory
      Parameters:
      messageHistoryFactory - the custom factory
    • getDebugger

      Debugger getDebugger()
      Gets the current Debugger
      Returns:
      the debugger
    • setDebugger

      void setDebugger(Debugger debugger)
      Sets a custom Debugger
      Parameters:
      debugger - the debugger
    • getTracer

      Tracer getTracer()
      Gets the current Tracer
      Returns:
      the tracer
    • setTracer

      void setTracer(Tracer tracer)
      Sets a custom Tracer
    • setTracingStandby

      void setTracingStandby(boolean tracingStandby)
      Whether to set tracing on standby. If on standby then the tracer is installed and made available. Then the tracer can be enabled later at runtime via JMX or via Tracer.setEnabled(boolean).
    • isTracingStandby

      boolean isTracingStandby()
      Whether to set tracing on standby. If on standby then the tracer is installed and made available. Then the tracer can be enabled later at runtime via JMX or via Tracer.setEnabled(boolean).
    • setBacklogTracingStandby

      void setBacklogTracingStandby(boolean backlogTracingStandby)
      Whether to set backlog tracing on standby. If on standby then the backlog tracer is installed and made available. Then the backlog tracer can be enabled later at runtime via JMX or via Java API.
    • isBacklogTracingStandby

      boolean isBacklogTracingStandby()
      Whether to set backlog tracing on standby. If on standby then the backlog tracer is installed and made available. Then the backlog tracer can be enabled later at runtime via JMX or via Java API.
    • setBacklogTracingTemplates

      void setBacklogTracingTemplates(boolean backlogTracingTemplates)
      Whether backlog tracing should trace inner details from route templates (or kamelets). Turning this off can reduce the verbosity of tracing when using many route templates, and allow to focus on tracing your own Camel routes only.
    • isBacklogTracingTemplates

      boolean isBacklogTracingTemplates()
      Whether backlog tracing should trace inner details from route templates (or kamelets). Turning this on increases the verbosity of tracing by including events from internal routes in the templates or kamelets.
    • getUuidGenerator

      UuidGenerator getUuidGenerator()
      Gets the current UuidGenerator
      Returns:
      the uuidGenerator
    • setUuidGenerator

      void setUuidGenerator(UuidGenerator uuidGenerator)
      Sets a custom UuidGenerator (should only be set once)
      Parameters:
      uuidGenerator - the UUID Generator
    • isLoadTypeConverters

      Boolean isLoadTypeConverters()
      Whether to load custom type converters by scanning classpath. This is used for backwards compatibility with Camel 2.x. Its recommended to migrate to use fast type converter loading by setting @Converter(loader = true) on your custom type converter classes.
    • setLoadTypeConverters

      void setLoadTypeConverters(Boolean loadTypeConverters)
      Whether to load custom type converters by scanning classpath. This is used for backwards compatibility with Camel 2.x. Its recommended to migrate to use fast type converter loading by setting @Converter(loader = true) on your custom type converter classes.
      Parameters:
      loadTypeConverters - whether to load custom type converters using classpath scanning.
    • isLoadHealthChecks

      Boolean isLoadHealthChecks()
      Whether to load custom health checks by scanning classpath.
    • setLoadHealthChecks

      void setLoadHealthChecks(Boolean loadHealthChecks)
      Whether to load custom health checks by scanning classpath.
    • isSourceLocationEnabled

      Boolean isSourceLocationEnabled()
      Whether to capture precise source location:line-number for all EIPs in Camel routes. Enabling this will impact parsing Java based routes (also Groovy, Kotlin, etc.) on startup as this uses StackTraceElement to calculate the location from the Camel route, which comes with a performance cost. This only impact startup, not the performance of the routes at runtime.
    • setSourceLocationEnabled

      void setSourceLocationEnabled(Boolean sourceLocationEnabled)
      Whether to capture precise source location:line-number for all EIPs in Camel routes. Enabling this will impact parsing Java based routes (also Groovy, Kotlin, etc.) on startup as this uses StackTraceElement to calculate the location from the Camel route, which comes with a performance cost. This only impact startup, not the performance of the routes at runtime.
    • isModeline

      Boolean isModeline()
      Whether camel-k style modeline is also enabled when not using camel-k. Enabling this allows to use a camel-k like experience by being able to configure various settings using modeline directly in your route source code.
    • setModeline

      void setModeline(Boolean modeline)
      Whether camel-k style modeline is also enabled when not using camel-k. Enabling this allows to use a camel-k like experience by being able to configure various settings using modeline directly in your route source code.
    • isDevConsole

      Boolean isDevConsole()
      Whether to enable developer console (requires camel-console on classpath). The developer console is only for assisting during development. This is NOT for production usage.
    • setDevConsole

      void setDevConsole(Boolean loadDevConsoles)
      Whether to enable developer console (requires camel-console on classpath) The developer console is only for assisting during development. This is NOT for production usage.
    • isTypeConverterStatisticsEnabled

      Boolean isTypeConverterStatisticsEnabled()
      Whether or not type converter statistics is enabled.

      By default the type converter utilization statistics is disabled. Notice: If enabled then there is a slight performance impact under very heavy load.

      Returns:
      true if enabled, false if disabled (default).
    • setTypeConverterStatisticsEnabled

      void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled)
      Sets whether or not type converter statistics is enabled.

      By default the type converter utilization statistics is disabled. Notice: If enabled then there is a slight performance impact under very heavy load.

      You can enable/disable the statistics at runtime using the {@link org.apache.camel.spi.TypeConverterRegistry#getStatistics()#setTypeConverterStatisticsEnabled(Boolean)} method, or from JMX on the org.apache.camel.api.management.mbean.ManagedTypeConverterRegistryMBean mbean.

      Parameters:
      typeConverterStatisticsEnabled - true to enable, false to disable
    • isUseMDCLogging

      Boolean isUseMDCLogging()
      Whether or not MDC logging is being enabled.
      Returns:
      true if MDC logging is enabled
    • setUseMDCLogging

      void setUseMDCLogging(Boolean useMDCLogging)
      Set whether MDC is enabled.
      Parameters:
      useMDCLogging - true to enable MDC logging, false to disable
    • getMDCLoggingKeysPattern

      String getMDCLoggingKeysPattern()
      Gets the pattern used for determine which custom MDC keys to propagate during message routing when the routing engine continues routing asynchronously for the given message. Setting this pattern to * will propagate all custom keys. Or setting the pattern to foo*,bar* will propagate any keys starting with either foo or bar. Notice that a set of standard Camel MDC keys are always propagated which starts with camel. as key name.

      The match rules are applied in this order (case insensitive):

      • exact match, returns true
      • wildcard match (pattern ends with a * and the name starts with the pattern), returns true
      • regular expression match, returns true
      • otherwise returns false
    • setMDCLoggingKeysPattern

      void setMDCLoggingKeysPattern(String pattern)
      Sets the pattern used for determine which custom MDC keys to propagate during message routing when the routing engine continues routing asynchronously for the given message. Setting this pattern to * will propagate all custom keys. Or setting the pattern to foo*,bar* will propagate any keys starting with either foo or bar. Notice that a set of standard Camel MDC keys are always propagated which starts with camel. as key name.

      The match rules are applied in this order (case insensitive):

      • exact match, returns true
      • wildcard match (pattern ends with a * and the name starts with the pattern), returns true
      • regular expression match, returns true
      • otherwise returns false
      Parameters:
      pattern - the pattern
    • getTracingLoggingFormat

      String getTracingLoggingFormat()
      To use a custom tracing logging format. The default format (arrow, routeId, label) is: %-4.4s [%-12.12s] [%-33.33s]
    • setTracingLoggingFormat

      void setTracingLoggingFormat(String format)
      To use a custom tracing logging format. The default format (arrow, routeId, label) is: %-4.4s [%-12.12s] [%-33.33s]
      Parameters:
      format - the logging format
    • setTracingTemplates

      void setTracingTemplates(boolean tracingTemplates)
      Whether tracing should trace inner details from route templates (or kamelets). Turning this on increases the verbosity of tracing by including events from internal routes in the templates or kamelets.
    • isTracingTemplates

      boolean isTracingTemplates()
      Whether tracing should trace inner details from route templates (or kamelets). Turning this off can reduce the verbosity of tracing when using many route templates, and allow to focus on tracing your own Camel routes only.
    • getDumpRoutes

      String getDumpRoutes()
      If dumping is enabled then Camel will during startup dump all loaded routes (incl rests and route templates) represented as XML DSL into the log. This is intended for trouble shooting or to assist during development. Sensitive information that may be configured in the route endpoints could potentially be included in the dump output and is therefore not recommended to be used for production usage. This requires to have camel-xml-jaxb on the classpath to be able to dump the routes as XML.
      Returns:
      xml, or yaml if dumping is enabled
    • setDumpRoutes

      void setDumpRoutes(String format)
      If dumping is enabled then Camel will during startup dump all loaded routes (incl rests and route templates) represented as XML/YAML DSL into the log. This is intended for trouble shooting or to assist during development. Sensitive information that may be configured in the route endpoints could potentially be included in the dump output and is therefore not recommended being used for production usage. This requires to have camel-xml-io/camel-yaml-io on the classpath to be able to dump the routes as XML/YAML.
      Parameters:
      format - xml or yaml
    • isUseDataType

      Boolean isUseDataType()
      Whether to enable using data type on Camel messages.

      Data type are automatic turned on if one or more routes has been explicit configured with input and output types. Otherwise, data type is default off.

      Returns:
      true if data type is enabled
    • setUseDataType

      void setUseDataType(Boolean useDataType)
      Whether to enable using data type on Camel messages.

      Data type are automatic turned on if one or more routes has been explicit configured with input and output types. Otherwise, data type is default off.

      Parameters:
      useDataType - true to enable data type on Camel messages.
    • isUseBreadcrumb

      Boolean isUseBreadcrumb()
      Whether or not breadcrumb is enabled.
      Returns:
      true if breadcrumb is enabled
    • setUseBreadcrumb

      void setUseBreadcrumb(Boolean useBreadcrumb)
      Set whether breadcrumb is enabled.
      Parameters:
      useBreadcrumb - true to enable breadcrumb, false to disable
    • getStreamCachingStrategy

      StreamCachingStrategy getStreamCachingStrategy()
      Gets the StreamCachingStrategy to use.
    • setStreamCachingStrategy

      void setStreamCachingStrategy(StreamCachingStrategy streamCachingStrategy)
      Sets a custom StreamCachingStrategy to use.
    • getRuntimeEndpointRegistry

      RuntimeEndpointRegistry getRuntimeEndpointRegistry()
      Gets the RuntimeEndpointRegistry to use, or null if none is in use.
    • setRuntimeEndpointRegistry

      void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry)
      Sets a custom RuntimeEndpointRegistry to use.
    • setSSLContextParameters

      void setSSLContextParameters(SSLContextParameters sslContextParameters)
      Sets the global SSL context parameters.
    • getSSLContextParameters

      SSLContextParameters getSSLContextParameters()
      Gets the global SSL context parameters if configured.
    • setStartupSummaryLevel

      void setStartupSummaryLevel(StartupSummaryLevel startupSummaryLevel)
      Controls the level of information logged during startup (and shutdown) of CamelContext.
    • getStartupSummaryLevel

      StartupSummaryLevel getStartupSummaryLevel()
      Controls the level of information logged during startup (and shutdown) of CamelContext.