Interface ContextServicePlugin


public interface ContextServicePlugin
A plugin interface that allows third-party components to perform initialization tasks when a CamelContext is being configured and started.

Implementations of this interface are automatically discovered and loaded via the Java ServiceLoader mechanism. To register a plugin, create a service provider configuration file at META-INF/services/org.apache.camel.spi.ContextServicePlugin containing the fully qualified class name of your implementation.

Common use cases include:

  • Registering beans in the Camel registry
  • Adding event notifiers for monitoring
  • Configuring global interceptors
  • Setting up custom type converters

Example Usage:

 
 public class MyContextServicePlugin implements ContextServicePlugin {
     @Override
     public void load(CamelContext camelContext) {
         // Register a bean in the registry
         camelContext.getRegistry().bind("myBean", new MyBean());

         // Add an event notifier
         camelContext.getManagementStrategy().addEventNotifier(new MyEventNotifier());
     }
 }
 
 
See Also:
  • invalid reference
    org.apache.camel.impl.engine.DefaultContextServiceLoaderPlugin
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    load(CamelContext camelContext)
    Called during CamelContext initialization to allow the plugin to configure or customize the context.
    default void
    onReload(CamelContext camelContext)
    Called before route reloading in development mode to allow the plugin to refresh its state.
    default void
    unload(CamelContext camelContext)
    Called during CamelContext stop.
  • Method Details

    • load

      void load(CamelContext camelContext)
      Called during CamelContext initialization to allow the plugin to configure or customize the context.

      This method is invoked after the CamelContext has been created but before routes are started. Implementations should perform any necessary setup operations such as registering beans, adding event notifiers, or configuring global settings.

      Parameters:
      camelContext - the CamelContext being initialized, never null
    • onReload

      default void onReload(CamelContext camelContext)
      Called before route reloading in development mode to allow the plugin to refresh its state.

      This method is invoked by the route watcher reload strategy before routes are reloaded, giving plugins the opportunity to refresh bean references, re-read configuration, or perform other updates that should happen before the new routes are started.

      The default implementation does nothing. Plugins that register beans or other resources that may become stale when properties change should override this method to refresh those resources.

      Parameters:
      camelContext - the CamelContext being reloaded, never null
    • unload

      default void unload(CamelContext camelContext)
      Called during CamelContext stop. Use it to free allocated resources.
      Parameters:
      camelContext - the CamelContext being uninitialized, never null