DuckDB
Since Camel 4.22
Only producer is supported
This component integrates with DuckDB using the official JDBC driver (org.duckdb:duckdb_jdbc). It focuses on embedded databases (:memory: or file paths), SQL execute/query, structured batch insert, file copy (CSV, Parquet, JSON), and ping.
While DuckDB can be used through JDBC and SQL, this component exposes DuckDB-oriented URI options and headers without hand-wiring JDBC URLs in every route.
Maven users will need to add the following dependency to their pom.xml:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-duckdb</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
duckdb:databasePath?[options]
Configure databasePath as :memory: or a file path, either relative (analytics.db) or absolute (/data/analytics.db). The default table for insert and copy is set with the table option. Alternatively set jdbcUrl=jdbc:duckdb:… to override the built URL, or autowire a shared javax.sql.DataSource.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The DuckDB component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Embedded database path (:memory: or a file path). Used when jdbcUrl is not set. | :memory: | String | |
Autowired Shared JDBC DataSource for all endpoints. | DataSource | ||
Full JDBC URL override (for example jdbc:duckdb:/path/to/db). When set, databasePath is ignored. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The DuckDB endpoint is configured using URI syntax:
duckdb:databasePath
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Batch size for insert when the body is a List. 0 inserts all rows in one JDBC batch. | 0 | int | |
File format for copy: csv, parquet, json or auto (inferred from the file extension). | auto | String | |
Full JDBC URL override. When set, databasePath is not used to build the URL. | String | ||
The operation to perform: execute, query, insert, copy or ping. Enum values:
| EXECUTE | DuckDbOperation | |
Static SQL for query when the message body is empty. | String | ||
Open the embedded database file in read-only mode. Only applies to connections created by this endpoint from databasePath or jdbcUrl, and requires an existing database file. | false | boolean | |
How query results are returned: LIST_MAP (List of Map) or JSON array string. Enum values:
| LIST_MAP | DuckDbResultFormat | |
Target table for insert and copy operations. Can be overridden per message with the CamelDuckDbTable header. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The DuckDB component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelDuckDbOperation (producer) Constant: | Overrides the operation configured on the endpoint. | String | |
CamelDuckDbDatabasePath (producer) Constant: | Overrides the database path configured on the endpoint. | String | |
| Constant: | Overrides the target table configured on the endpoint. | String | |
| Constant: | Overrides the SQL for query or execute operations. | String | |
CamelDuckDbRowsWritten (producer) Constant: | The number of rows written or affected. | long | |
CamelDuckDbRowsRead (producer) Constant: | The number of rows returned by a query. | long | |
| Constant: | The boolean result of a ping operation. | boolean |
Operations
The producer supports:
-
execute(default) — run DDL/DML from the message body (orqueryoption /CamelDuckDbQueryheader) -
query— run a SELECT and return rows asList<Map>(default) or JSON (resultFormat=JSON) -
insert— insert aListofMaprows intotable -
copy— bulk load from aFileor pathStringusing DuckDBread_csv/read_parquet/read_json -
ping—SELECT 1connectivity check; setsCamelDuckDbPingOk
The endpoint reuses one JDBC connection for its configured databasePath / jdbcUrl and serializes access for thread safety. Prefer a shared DataSource when you need concurrent producers. Set the CamelDuckDbDatabasePath header to open a short-lived connection to a different database file for a single message.