A plugin extension for Apache Camel that provides opinionated bean factories for simplified component configuration across various domains including AI, JDBC, and other bean-based components.
Forage is a plugin extension that simplifies Apache Camel configuration by providing opinionated bean factories. Instead of manually configuring beans, you choose the appropriate factory and configure it through properties files, environment variables, or system properties. The library offers seamless integration with various components including AI models, JDBC data sources, chat memory providers, and agent factories through a factory-based approach that requires no Java code instantiation.
- Opinionated bean factories - Pre-configured factory classes that eliminate manual bean configuration
- Configuration-driven - Configure beans through properties files, environment variables, or system properties
- Multiple provider support - Support for various AI models (OpenAI, Google Gemini, Ollama), JDBC databases, and extensible for other providers
- ServiceLoader-based discovery - Automatic factory discovery with no manual wiring required
- Modular architecture - Pick only the modules you need
- Zero Java code instantiation - Everything configurable through properties
Add the desired modules to your project. For example, to use the default agent factory with OpenAI:
<!--This component provides support for OpenAI models (GPT-3.5, GPT-4, etc.)-->
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-model-open-ai</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--This component provides support for the message window chat memory -->
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-memory-message-window</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--This component adds agent factories for single and multi-agent systems -->
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-agent-factories</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--This component adds the composable agent implementation -->
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-agent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>Simply reference the bean class in your Camel route:
from("direct:start")
.to("langchain4j-agent:test-memory-agent?agentFactory=#class:io.kaoto.forage.agent.factory.MultiAgentFactory");The io.kaoto.forage.agent.factory.MultiAgentFactory class is a factory that builds AI agents automatically based on the dependencies available on the classpath and configured through properties. It supports both single-agent and multi-agent configurations.
- forage-core-ai - Core interfaces and abstractions for AI components
- forage-core-agent - Agent interfaces and base classes
- forage-agent-factories - Agent factories for single and multi-agent systems (Documentation)
- forage-agent - Composable agent implementation with optional memory support (Documentation)
π Complete Agents Documentation - Comprehensive guide to all agent components
- camel-forage-model-open-ai - OpenAI chat model provider (Configuration Guide)
- forage-model-google-gemini - Google Gemini chat model provider (Configuration Guide)
- forage-model-ollama - Ollama chat model provider (Configuration Guide)
- forage-memory-message-window - Message window chat memory with persistent storage
- forage-vectordb-default - Core vector database functionality
- forage-vectordb-chroma - Chroma vector database provider
- forage-vectordb-infinispan - Infinispan vector database provider
- forage-vectordb-mariadb - MariaDB vector database provider
- forage-vectordb-milvus - Milvus vector database provider
- forage-vectordb-neo4j - Neo4j vector database provider
- forage-vectordb-pgvector - Postgres Vector vector database provider
- forage-vectordb-qdrant - Qdrant vector database provider
- forage-vectordb-redis - Redis vector database provider
- forage-vectordb-weaviate - Weaviate vector database prodiver
- embeddings - Embedding model providers (coming soon)
Forage provides JDBC data source factories that simplify database connectivity with pre-configured, pooled data sources for various database systems.
- forage-jdbc - Core pooled JDBC functionality
- forage-jdbc-factories - Data source factory implementations
- forage-jdbc-postgres - PostgreSQL data source provider
- forage-jdbc-mysql - MySQL data source provider
- forage-jdbc-mariadb - MariaDB data source provider
- forage-jdbc-oracle - Oracle data source provider
- forage-jdbc-mssql - Microsoft SQL Server data source provider
- forage-jdbc-db2 - IBM DB2 data source provider
- forage-jdbc-h2 - H2 database data source provider
- forage-jdbc-hsqldb - HSQLDB data source provider
All JDBC modules support the following configuration properties with a flexible precedence hierarchy (environment variables β system properties β configuration files β defaults):
Database Connection:
jdbc.url- JDBC connection URL (required)jdbc.username- Database username (required)jdbc.password- Database password (required)
Connection Pool Settings:
jdbc.pool.initial.size- Initial pool size (default: 5)jdbc.pool.min.size- Minimum pool size (default: 2)jdbc.pool.max.size- Maximum pool size (default: 20)jdbc.pool.acquisition.timeout.seconds- Connection acquisition timeout (default: 5)jdbc.pool.validation.timeout.seconds- Connection validation timeout (default: 3)jdbc.pool.leak.timeout.minutes- Connection leak detection timeout (default: 10)jdbc.pool.idle.validation.timeout.minutes- Idle connection validation timeout (default: 3)
Transaction Settings:
jdbc.transaction.timeout.seconds- Transaction timeout (default: 30)
Provider Configuration:
provider.datasource.class- DataSource implementation class (auto-detected based on dependencies)
- Start PostgreSQL database:
camel infra run postgres- Add dependencies to your project:
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-jdbc-factories</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.kaoto.forage</groupId>
<artifactId>forage-jdbc-postgres</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>- Create a Camel route:
import org.apache.camel.builder.RouteBuilder;
public class Test extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:java?period=1000")
.to("sql:select * from acme?dataSourceFactory=#class:io.kaoto.forage.jdbc.factory.DefaultDataSourceFactory")
.log("${body}");
}
}- Run with JBang:
camel run Test.java \
--dep=mvn:io.kaoto.forage:forage-jdbc-factories:1.0-SNAPSHOT \
--dep=mvn:io.kaoto.forage:forage-jdbc-postgres:1.0-SNAPSHOTThis provides a fully configured, pooled data source out-of-the-box with sensible defaults.
Environment Variables:
export JDBC_URL="jdbc:postgresql://localhost:5432/mydb"
export JDBC_USERNAME="myuser"
export JDBC_PASSWORD="mypassword"
export JDBC_POOL_MAX_SIZE="50"System Properties:
-Djdbc.url=jdbc:postgresql://localhost:5432/mydb
-Djdbc.username=myuser
-Djdbc.password=mypassword
-Djdbc.pool.max.size=50Configuration File (forage-datasource-factory.properties):
jdbc.url=jdbc:postgresql://localhost:5432/mydb
jdbc.username=myuser
jdbc.password=mypassword
jdbc.pool.max.size=50Forage uses a flexible configuration system that supports multiple sources with a defined precedence hierarchy:
- Environment variables (highest precedence)
- System properties
- Configuration files (e.g.,
forage-model-*.properties) - Default values (where applicable)
Each AI model provider has its own configuration requirements and options. For detailed configuration instructions, including environment variables, system properties, and configuration files, please refer to the respective model documentation:
- OpenAI: See OpenAI Configuration Guide
- Google Gemini: See Google Gemini Configuration Guide
- Ollama: See Ollama Configuration Guide
For immediate setup, here are minimal configuration examples:
export OPENAI_API_KEY="sk-your-api-key-here"
export OPENAI_MODEL_NAME="gpt-4" # Optional, defaults to gpt-3.5-turboexport GOOGLE_API_KEY="your-google-api-key"
export GOOGLE_MODEL_NAME="gemini-pro"export OLLAMA_BASE_URL="http://localhost:11434" # Optional, this is the default
export OLLAMA_MODEL_NAME="llama3" # Optional, this is the defaultForage uses a ServiceLoader-based discovery mechanism with opinionated bean factories:
- Bean Factories - Factory classes that create configured beans (DataSourceFactory, AgentFactory, ModelProvider, etc.)
- Configuration System - Properties-based configuration with environment variable and system property support
- ServiceLoader Discovery - Automatic factory discovery without manual wiring
- Catalog Integration - Build-time catalog generation for tooling integration (e.g., Kaoto)
Factories automatically discover and combine components using Java's ServiceLoader mechanism, with all configuration handled through properties rather than Java code.
Example for a memory-less agent.
from("timer:ai?period=30000")
.setBody(constant("Tell me a joke"))
.to("langchain4j-agent:joke-agent?agentFactory=#class:io.kaoto.forage.agent.factory.MultiAgentFactory")
.log("AI Response: ${body}");public class MyRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:chat")
.to("langchain4j-agent:chat-agent?agentFactory=#class:io.kaoto.forage.agent.factory.MultiAgentFactory")
.log("Chat response: ${body}");
}
}- Java 17+
- Apache Camel 4.14.0+
- LangChain4j 1.2.0+
This project follows standard Maven conventions. To build:
mvn clean installIf you're developing Apache Camel components and want to integrate them with the Forage library, or if you want to create new providers for AI models, vector databases, or other services, please refer to our comprehensive Contributing Beans Guide.
This guide is essential reading for:
- Component developers who want to add factory-based configuration to their Apache Camel components
- Library contributors who want to create new AI model providers, vector database integrations, or other service providers
- Maintainers who need to understand the architecture and patterns used throughout the Forage library
This project is licensed under the Apache License 2.0.