Skip to content

Plugin SPI Contract

Module: camel-integration-capability-pluginInterface: org.apache.camel.spi.ContextServicePlugin

Discovery

File: META-INF/services/org.apache.camel.spi.ContextServicePlugin

Content:

ai.wanaku.capability.camel.plugin.CamelIntegrationPlugin

Interface Implementation

java
package ai.wanaku.capability.camel.plugin;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.ContextServicePlugin;

public class CamelIntegrationPlugin implements ContextServicePlugin {

    /**
     * Called after CamelContext creation, before routes start.
     *
     * Responsibilities:
     * 1. Load configuration from properties/environment
     * 2. Initialize data directory
     * 3. Run initializers (e.g., git clone)
     * 4. Download resources if needed
     * 5. Start gRPC server
     * 6. Register with discovery service
     *
     * @param camelContext The Camel context being initialized
     */
    @Override
    public void load(CamelContext camelContext) {
        // Implementation
    }

    /**
     * Called during CamelContext shutdown.
     *
     * Responsibilities:
     * 1. Deregister from discovery service
     * 2. Stop gRPC server
     * 3. Release resources
     *
     * @param camelContext The Camel context being stopped
     */
    @Override
    public void unload(CamelContext camelContext) {
        // Implementation
    }
}

Configuration Contract

Properties File

Location: Classpath resource camel-integration-capability.properties

PropertyTypeRequiredDefaultDescription
registration.urlStringYes-Wanaku registration endpoint URL
registration.announce.addressStringNoautoAddress announced to discovery service
grpc.portIntegerNo9190gRPC server port
service.nameStringNocamelService name for registration
routes.refStringYes-Reference to Camel routes YAML
rules.refStringNo-Reference to exposure rules YAML
token.endpointStringNo-OAuth token endpoint
client.idStringYes-OAuth client ID
client.secretStringYes-OAuth client secret
dependenciesStringNo-Comma-separated dependency refs
repositoriesStringNo-Comma-separated repository URLs
init.fromStringNo-Git repository URL to clone
data.dirStringNo/tmpData directory path

Environment Variable Override

Each property can be overridden by environment variable. Environment variables take precedence.

PropertyEnvironment Variable
registration.urlREGISTRATION_URL
registration.announce.addressREGISTRATION_ANNOUNCE_ADDRESS
grpc.portGRPC_PORT
service.nameSERVICE_NAME
routes.refROUTES_PATH
rules.refROUTES_RULES
token.endpointTOKEN_ENDPOINT
client.idCLIENT_ID
client.secretCLIENT_SECRET
dependenciesDEPENDENCIES
repositoriesREPOSITORIES
init.fromINIT_FROM
data.dirDATA_DIR

Error Handling

ConditionBehavior
Missing required propertyThrow IllegalStateException with clear message
Invalid property valueThrow IllegalArgumentException with validation details
Resource download failureLog error, retry based on configuration
gRPC server start failureThrow exception, prevent context start
Discovery registration failureLog warning, continue (non-fatal)

Thread Safety

  • load() and unload() are called from Camel context lifecycle thread
  • Internal state must be thread-safe for concurrent gRPC requests
  • Use volatile or synchronization for mutable state