Google Firestore
Since Camel 4.19
Both producer and consumer are supported
The Google Firestore component provides access to Google Cloud Firestore via the Google Cloud Firestore Java library.
Firestore is a flexible, scalable NoSQL cloud database for mobile, web, and server development. It keeps your data in sync across client apps through realtime listeners and offers offline support.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-google-firestore</artifactId>
<!-- use the same version as your Camel core version -->
<version>x.x.x</version>
</dependency> Authentication Configuration
Google Firestore component authentication is targeted for use with GCP Service Accounts. For more information, please refer to Google Firestore Quickstart.
When you have the service account key, you can provide authentication credentials to your application code. Google security credentials can be set through the component endpoint:
String endpoint = "google-firestore://myCollection?serviceAccountKey=/home/user/Downloads/my-key.json&projectId=my-project"; Or by providing the path to the GCP credentials file location:
Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
URI Format
google-firestore://collectionName?[options]
You can append query options to the URI in the following format: ?options=value&option2=value&…
For example, to get a document from the users collection:
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=getDocumentById&serviceAccountKey=/path/to/key.json&projectId=my-project")
.to("log:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=getDocumentById&serviceAccountKey=/path/to/key.json&projectId=my-project"/>
<to uri="log:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: getDocumentById
serviceAccountKey: /path/to/key.json
projectId: my-project
- to:
uri: log:result 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 Google Firestore component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The configuration that each endpoint of this component starts from. The options of the endpoint URI override its values. | GoogleFirestoreConfiguration | ||
The Firestore database ID. If not specified, the default database '(default)' will be used. | String | ||
Autowired To use a custom com.google.cloud.firestore.Firestore client. When this option is set or autowired, the projectId, databaseId and serviceAccountKey options are not used. The Camel endpoint does not close a client that is set or autowired. | Firestore | ||
The ID of the Google Cloud project. If not set, the Firestore client takes it from the service account key, or from the environment, such as the GOOGLE_CLOUD_PROJECT environment variable. | String | ||
The service account key file in JSON format that the Firestore client uses as credentials. It is loaded from the classpath by default, or from another location with the prefix file: or http:. If not set, the client uses Application Default Credentials. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the consumer listens for realtime changes of the collection with a snapshot listener. The first snapshot reports every existing document as ADDED, and each poll routes the changes buffered since the previous poll. If false, each poll reads all documents of the collection, so a document is consumed again in every poll. | false | boolean | |
Maximum number of realtime document changes buffered between two polls. The changes reported by the snapshot listener are buffered until the next poll picks them up, so a collection changing faster than the route consumes it makes that buffer grow. When the buffer is full the oldest buffered change is discarded and a warning is logged. Use 0 for an unbounded buffer. Only used when realtimeUpdates is enabled. | 0 | int | |
The ID of the document for setDocument, getDocumentById, updateDocument and deleteDocument, which fail without one. For listCollections it is the document whose subcollections are listed, and if not set the root collections are listed. The CamelGoogleFirestoreDocumentId header replaces this option. | 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 | |
The operation that the producer performs. If not set, the producer performs setDocument. The CamelGoogleFirestoreOperation header replaces this option. Enum values:
| setDocument | GoogleFirestoreOperations | |
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 | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean |
Endpoint Options
The Google Firestore endpoint is configured using URI syntax:
google-firestore:collectionName
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The Firestore database ID. If not specified, the default database '(default)' will be used. | String | ||
Autowired To use a custom com.google.cloud.firestore.Firestore client. When this option is set or autowired, the projectId, databaseId and serviceAccountKey options are not used. The Camel endpoint does not close a client that is set or autowired. | Firestore | ||
The ID of the Google Cloud project. If not set, the Firestore client takes it from the service account key, or from the environment, such as the GOOGLE_CLOUD_PROJECT environment variable. | String | ||
The service account key file in JSON format that the Firestore client uses as credentials. It is loaded from the classpath by default, or from another location with the prefix file: or http:. If not set, the client uses Application Default Credentials. | String | ||
Whether the consumer listens for realtime changes of the collection with a snapshot listener. The first snapshot reports every existing document as ADDED, and each poll routes the changes buffered since the previous poll. If false, each poll reads all documents of the collection, so a document is consumed again in every poll. | false | boolean | |
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Maximum number of realtime document changes buffered between two polls. The changes reported by the snapshot listener are buffered until the next poll picks them up, so a collection changing faster than the route consumes it makes that buffer grow. When the buffer is full the oldest buffered change is discarded and a warning is logged. Use 0 for an unbounded buffer. Only used when realtimeUpdates is enabled. | 0 | int | |
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
The ID of the document for setDocument, getDocumentById, updateDocument and deleteDocument, which fail without one. For listCollections it is the document whose subcollections are listed, and if not set the root collections are listed. The CamelGoogleFirestoreDocumentId header replaces this option. | String | ||
The operation that the producer performs. If not set, the producer performs setDocument. The CamelGoogleFirestoreOperation header replaces this option. Enum values:
| setDocument | GoogleFirestoreOperations | |
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 | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
Message Headers
The Google Firestore component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelGoogleFirestoreOperation (producer) Constant: | The operation that the producer performs. It replaces the operation option. Enum values:
| GoogleFirestoreOperations | |
CamelGoogleFirestoreCollectionName (producer) Constant: | The name of the collection that the producer uses. It replaces the collection name of the endpoint URI. | String | |
CamelGoogleFirestoreDocumentId (producer) Constant: | The ID of the document that the producer uses. It replaces the documentId option. | String | |
CamelGoogleFirestoreQueryField (producer) Constant: | The field that queryCollection filters on. The filter is applied only when the CamelGoogleFirestoreQueryOperator and CamelGoogleFirestoreQueryValue headers are also set. | String | |
CamelGoogleFirestoreQueryOperator (producer) Constant: | The operator for query filtering: == (or eq), != (or ne), lt (less than), lte (less than or equal), gt (greater than), gte (greater than or equal), array-contains, in, array-contains-any or not-in. The lt, lte, gt and gte operators can also be given as their comparison symbols. | String | |
CamelGoogleFirestoreQueryValue (producer) Constant: | The value that queryCollection compares the field with. For the in, array-contains-any and not-in operators it must be a java.util.List. | Object | |
CamelGoogleFirestoreQueryLimit (producer) Constant: | The maximum number of documents that queryCollection returns. If not set, or 0 or less, all matching documents are returned. | Integer | |
CamelGoogleFirestoreQueryOrderBy (producer) Constant: | The field that queryCollection orders the documents by. | String | |
CamelGoogleFirestoreQueryOrderDirection (producer) Constant: | The direction of the order that CamelGoogleFirestoreQueryOrderBy sets: ASCENDING (the default) or DESCENDING. Enum values:
| Query$Direction | |
CamelGoogleFirestoreResponseDocumentId (common) Constant: | The ID of the document. The consumer sets it for each document, and the producer for setDocument, createDocument (the generated ID), getDocumentById, updateDocument and deleteDocument. | String | |
CamelGoogleFirestoreResponseDocumentPath (common) Constant: | The path of the document, such as users/alice. The consumer sets it for each document, and the producer for setDocument, createDocument, updateDocument, deleteDocument, and getDocumentById when the document exists. | String | |
CamelGoogleFirestoreResponseCreateTime (common) Constant: | The time the document was created. The consumer sets it for each document, and the producer for getDocumentById when the document exists. | Timestamp | |
CamelGoogleFirestoreResponseUpdateTime (common) Constant: | The time the document was last updated. The consumer sets it for each document, and the producer for getDocumentById when the document exists. For setDocument, createDocument, updateDocument and deleteDocument it is the time of the write. | Timestamp | |
CamelGoogleFirestoreResponseReadTime (common) Constant: | The time the document was read. The consumer sets it for each document, and the producer for getDocumentById when the document exists. | Timestamp | |
CamelGoogleFirestoreChangeType (consumer) Constant: | The type of change reported by the realtime listener: ADDED, MODIFIED or REMOVED. Only set when realtimeUpdates is enabled. | String | |
CamelGoogleFirestoreMerge (producer) Constant: | Whether setDocument merges the fields of the body into the existing document instead of replacing the document. | false | Boolean |
CamelGoogleFirestoreMergeFields (producer) Constant: | The names of the fields that setDocument merges when CamelGoogleFirestoreMerge is true. A dotted name such as address.city is the nested field city of address; a com.google.cloud.firestore.FieldPath element is used as it is. The other fields of the body are ignored. If not set, all fields of the body are merged. | List |
Message Body
The message body at each side of the Google Firestore component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The fields of the document as a Map, one message per document, with its id, path and times in headers, and with realtimeUpdates the change type. Numbers are Long or Double, a timestamp a com.google.cloud.Timestamp. |
Producer input |
| The fields to write for setDocument (the default), createDocument and updateDocument: a Map, or JSON object text, which is parsed into a Map. Bytes, a stream, a List, a POJO or no body fail: unmarshal it first. The other operations take their input from options and headers. Not known when |
Producer output |
| The Map of the fields written for setDocument, createDocument and updateDocument (JSON text is now the parsed Map), with the document id and path in headers. By the operation: the fields of the document or null when it does not exist for getDocumentById, true for deleteDocument, a List of Maps with _id and _path entries for queryCollection and listDocuments, and the collection ids for listCollections.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Google Firestore Producer Operations
Google Firestore component provides the following operations on the producer side:
-
setDocument- Create or overwrite a document with a specific ID -
createDocument- Create a new document with an auto-generated ID -
getDocumentById- Retrieve a document by its ID -
updateDocument- Update specific fields of a document -
deleteDocument- Delete a document -
queryCollection- Query documents with filters -
listDocuments- List all documents in a collection -
listCollections- List all collections
If you don’t specify an operation explicitly, the producer will perform a setDocument operation.
Supported Input Formats
For operations that require document data (setDocument, createDocument, updateDocument), the component accepts the following input formats:
-
Map<String, Object> - Java Map with field names as keys
-
JSON String - A valid JSON object string (e.g.,
{"name": "John", "age": 30}) -
Any object - Convertible to Map via Camel’s type converter
JSON String Example:
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"age\":30,\"active\":true}"))
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=setDocument"); <route>
<from uri="direct:start"/>
<setBody>
<constant>{"name":"John Doe","email":"john@example.com","age":30,"active":true}</constant>
</setBody>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=setDocument"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: '{"name":"John Doe","email":"john@example.com","age":30,"active":true}'
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: setDocument Google Firestore Consumer
The consumer can poll documents from a collection or listen for real-time updates.
-
Polling mode (default): Periodically polls the collection for all documents
-
Real-time mode: Listens for document changes using Firestore’s real-time listeners
To enable real-time updates:
-
Java
-
XML
-
YAML
from("google-firestore://myCollection?realtimeUpdates=true")
.to("log:changes"); <route>
<from uri="google-firestore://myCollection?realtimeUpdates=true"/>
<to uri="log:changes"/>
</route> - route:
from:
uri: google-firestore://myCollection
parameters:
realtimeUpdates: true
steps:
- to:
uri: log:changes In real-time mode the document changes reported by the listener are buffered until the next poll picks them up. That buffer is unbounded by default, so a collection changing faster than the route consumes it makes the buffer grow, and it keeps growing while the route is suspended. Set maxPendingChanges to bound it: when the buffer is full the oldest buffered change is discarded and a warning is logged, which leaves the route with the most recent state of the collection.
from("google-firestore://myCollection?realtimeUpdates=true&maxPendingChanges=1000")
.to("log:changes"); When the consumer starts, it waits up to 30 seconds for the first snapshot of the listener. If the listener reports an error instead, for example missing permissions or a database that does not exist, the consumer fails to start with that error. Firestore does not call a listener again after an error, so an error that comes later goes to the exception handler of the consumer (or to the routing error handler with bridgeErrorHandler=true), and the route must be restarted to listen again.
Advanced Component Configuration
If you need more control over the Firestore client instance configuration, you can create your own instance and refer to it in your Camel google-firestore component configuration:
-
Java
-
XML
-
YAML
from("google-firestore://myCollection?firestoreClient=#myFirestoreClient")
.to("mock:result"); <route>
<from uri="google-firestore://myCollection?firestoreClient=#myFirestoreClient"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: google-firestore://myCollection
parameters:
firestoreClient: "#myFirestoreClient"
steps:
- to:
uri: mock:result Producer Operation Examples
Create Document with Auto-Generated ID
This operation creates a new document with an auto-generated unique ID:
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("{\"name\":\"John Doe\",\"email\":\"john@example.com\",\"age\":30}"))
.to("google-firestore://users?operation=createDocument")
.log("Created document with ID: ${header.CamelGoogleFirestoreResponseDocumentId}"); <route>
<from uri="direct:start"/>
<setBody>
<constant>{"name":"John Doe","email":"john@example.com","age":30}</constant>
</setBody>
<to uri="google-firestore://users?operation=createDocument"/>
<log message="Created document with ID: ${header.CamelGoogleFirestoreResponseDocumentId}"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: '{"name":"John Doe","email":"john@example.com","age":30}'
- to:
uri: google-firestore://users
parameters:
operation: createDocument
- log:
message: "Created document with ID: ${header.CamelGoogleFirestoreResponseDocumentId}" Set Document with Specific ID
This operation creates or overwrites a document with a specific ID:
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("{\"name\":\"Jane Doe\",\"email\":\"jane@example.com\"}"))
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=setDocument")
.log("Document saved"); <route>
<from uri="direct:start"/>
<setBody>
<constant>{"name":"Jane Doe","email":"jane@example.com"}</constant>
</setBody>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=setDocument"/>
<log message="Document saved"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: '{"name":"Jane Doe","email":"jane@example.com"}'
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: setDocument
- log:
message: "Document saved" Set Document with Merge
To merge data with an existing document instead of overwriting:
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("{\"lastLogin\":\"2025-01-15T10:30:00Z\"}"))
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.setHeader("CamelGoogleFirestoreMerge", constant(true))
.to("google-firestore://users?operation=setDocument")
.log("Document merged"); <route>
<from uri="direct:start"/>
<setBody>
<constant>{"lastLogin":"2025-01-15T10:30:00Z"}</constant>
</setBody>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<setHeader name="CamelGoogleFirestoreMerge">
<constant>true</constant>
</setHeader>
<to uri="google-firestore://users?operation=setDocument"/>
<log message="Document merged"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: '{"lastLogin":"2025-01-15T10:30:00Z"}'
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- setHeader:
name: CamelGoogleFirestoreMerge
constant: true
- to:
uri: google-firestore://users
parameters:
operation: setDocument
- log:
message: "Document merged" Get Document by ID
This operation retrieves a document by its ID:
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=getDocumentById")
.log("Document data: ${body}"); <route>
<from uri="direct:start"/>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=getDocumentById"/>
<log message="Document data: ${body}"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: getDocumentById
- log:
message: "Document data: ${body}" The response body will contain a Map<String, Object> with the document data, or null if the document doesn’t exist.
Update Document
This operation updates specific fields without overwriting the entire document:
-
Java
-
XML
-
YAML
from("direct:start")
.setBody(constant("{\"status\":\"active\",\"updatedAt\":\"2025-01-15T10:30:00Z\"}"))
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=updateDocument")
.log("Document updated"); <route>
<from uri="direct:start"/>
<setBody>
<constant>{"status":"active","updatedAt":"2025-01-15T10:30:00Z"}</constant>
</setBody>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=updateDocument"/>
<log message="Document updated"/>
</route> - route:
from:
uri: direct:start
steps:
- setBody:
constant: '{"status":"active","updatedAt":"2025-01-15T10:30:00Z"}'
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: updateDocument
- log:
message: "Document updated" Delete Document
This operation deletes a document:
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=deleteDocument")
.log("Document deleted: ${body}"); <route>
<from uri="direct:start"/>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=deleteDocument"/>
<log message="Document deleted: ${body}"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: deleteDocument
- log:
message: "Document deleted: ${body}" List Documents
This operation lists all documents in a collection:
-
Java
-
XML
-
YAML
from("direct:start")
.to("google-firestore://users?operation=listDocuments")
.log("Found ${body.size()} documents"); <route>
<from uri="direct:start"/>
<to uri="google-firestore://users?operation=listDocuments"/>
<log message="Found ${body.size()} documents"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: google-firestore://users
parameters:
operation: listDocuments
- log: "Found ${body.size()} documents" The response body will contain a List<Map<String, Object>> with each document’s data. Each document includes _id and _path fields with the document ID and path.
Query Collection
This operation queries documents with filters:
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelGoogleFirestoreQueryField", constant("age"))
.setHeader("CamelGoogleFirestoreQueryOperator", constant(">="))
.setHeader("CamelGoogleFirestoreQueryValue", constant(21))
.setHeader("CamelGoogleFirestoreQueryLimit", constant(10))
.setHeader("CamelGoogleFirestoreQueryOrderBy", constant("age"))
.to("google-firestore://users?operation=queryCollection")
.log("Found ${body.size()} matching documents"); <route>
<from uri="direct:start"/>
<setHeader name="CamelGoogleFirestoreQueryField">
<constant>age</constant>
</setHeader>
<setHeader name="CamelGoogleFirestoreQueryOperator">
<constant>>=</constant>
</setHeader>
<setHeader name="CamelGoogleFirestoreQueryValue">
<constant>21</constant>
</setHeader>
<setHeader name="CamelGoogleFirestoreQueryLimit">
<constant>10</constant>
</setHeader>
<setHeader name="CamelGoogleFirestoreQueryOrderBy">
<constant>age</constant>
</setHeader>
<to uri="google-firestore://users?operation=queryCollection"/>
<log message="Found ${body.size()} matching documents"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelGoogleFirestoreQueryField
constant: age
- setHeader:
name: CamelGoogleFirestoreQueryOperator
constant: ">="
- setHeader:
name: CamelGoogleFirestoreQueryValue
constant: "21"
- setHeader:
name: CamelGoogleFirestoreQueryLimit
constant: "10"
- setHeader:
name: CamelGoogleFirestoreQueryOrderBy
constant: age
- to:
uri: google-firestore://users
parameters:
operation: queryCollection
- log:
message: "Found ${body.size()} matching documents" Supported query operators:
-
==oreq- Equal to -
!=orne- Not equal to -
<orlt- Less than -
⇐orlte- Less than or equal to -
>orgt- Greater than -
>=orgte- Greater than or equal to -
array-contains- Array contains value -
in- Value in list -
array-contains-any- Array contains any value in list -
not-in- Value not in list
List Collections
This operation lists all collections in the database:
-
Java
-
XML
-
YAML
from("direct:start")
.to("google-firestore://anyCollection?operation=listCollections")
.log("Collections: ${body}"); <route>
<from uri="direct:start"/>
<to uri="google-firestore://anyCollection?operation=listCollections"/>
<log message="Collections: ${body}"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: google-firestore://anyCollection
parameters:
operation: listCollections
- log: "Collections: ${body}" To list subcollections under a specific document:
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=listCollections")
.log("Subcollections: ${body}"); <route>
<from uri="direct:start"/>
<setHeader name="CamelGoogleFirestoreDocumentId">
<constant>user123</constant>
</setHeader>
<to uri="google-firestore://users?operation=listCollections"/>
<log message="Subcollections: ${body}"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelGoogleFirestoreDocumentId
constant: user123
- to:
uri: google-firestore://users
parameters:
operation: listCollections
- log:
message: "Subcollections: ${body}" Consumer Examples
Poll Documents
Poll all documents from a collection every 30 seconds:
-
Java
-
XML
-
YAML
from("google-firestore://users?delay=30000")
.log("Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}")
.log("Document data: ${body}")
.to("mock:result"); <route>
<from uri="google-firestore://users?delay=30000"/>
<log message="Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}"/>
<log message="Document data: ${body}"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: google-firestore://users
parameters:
delay: 30000
steps:
- log: "Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}"
- log: "Document data: ${body}"
- to:
uri: mock:result Real-time Updates
Listen for document changes in real-time:
-
Java
-
XML
-
YAML
from("google-firestore://users?realtimeUpdates=true")
.log("Change type: ${header.CamelGoogleFirestoreChangeType}")
.log("Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}")
.log("Document data: ${body}")
.to("mock:result"); <route>
<from uri="google-firestore://users?realtimeUpdates=true"/>
<log message="Change type: ${header.CamelGoogleFirestoreChangeType}"/>
<log message="Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}"/>
<log message="Document data: ${body}"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: google-firestore://users
parameters:
realtimeUpdates: true
steps:
- log: "Change type: ${header.CamelGoogleFirestoreChangeType}"
- log: "Document ID: ${header.CamelGoogleFirestoreResponseDocumentId}"
- log: "Document data: ${body}"
- to:
uri: mock:result The CamelGoogleFirestoreChangeType header indicates the type of change: ADDED, MODIFIED, or REMOVED.
Data Types
Input Data Formats
For write operations (setDocument, createDocument, updateDocument), the component accepts the following input formats in the message body:
| Format | Description | Example |
|---|---|---|
| Java Map with field names as keys |
|
JSON String | Valid JSON object string |
|
POJO | Any object convertible to Map via Camel’s type converter | Custom Java beans |
JSON String Input
You can send a JSON string directly as the message body. The component will automatically parse it:
// Simple JSON
from("direct:start")
.setBody(constant("{\"name\": \"John\", \"age\": 30}"))
.setHeader("CamelGoogleFirestoreDocumentId", constant("user123"))
.to("google-firestore://users?operation=setDocument");
// Multi-line JSON with text blocks (Java 15+)
String json = """
{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"active": true,
"tags": ["admin", "user"],
"address": {
"street": "123 Main St",
"city": "New York",
"zip": "10001"
}
}
""";
from("direct:start")
.setBody(constant(json))
.to("google-firestore://users?operation=createDocument"); Reading JSON from Files
-
Java
-
XML
-
YAML
from("file:data/users?noop=true&include=.*\\.json")
.setHeader("CamelGoogleFirestoreDocumentId", simple("${file:name.noext}"))
.to("google-firestore://users?operation=setDocument")
.log("Imported: ${file:name}"); <route>
<from uri="file:data/users?noop=true&include=.*\.json"/>
<setHeader name="CamelGoogleFirestoreDocumentId">
<simple>${file:name.noext}</simple>
</setHeader>
<to uri="google-firestore://users?operation=setDocument"/>
<log message="Imported: ${file:name}"/>
</route> - route:
from:
uri: file:data/users
parameters:
noop: true
include: ".*\\.json"
steps:
- setHeader:
name: CamelGoogleFirestoreDocumentId
simple: "${file:name.noext}"
- to:
uri: google-firestore://users
parameters:
operation: setDocument
- log:
message: "Imported: ${file:name}" REST API Integration
-
Java
-
XML
-
YAML
from("rest:post:/api/users")
.to("google-firestore://users?operation=createDocument")
.setBody(simple("{\"id\": \"${header.CamelGoogleFirestoreResponseDocumentId}\"}")); <route>
<from uri="rest:post:/api/users"/>
<to uri="google-firestore://users?operation=createDocument"/>
<setBody>
<simple>{"id": "${header.CamelGoogleFirestoreResponseDocumentId}"}</simple>
</setBody>
</route> - route:
from:
uri: rest:post:/api/users
steps:
- to:
uri: google-firestore://users
parameters:
operation: createDocument
- setBody:
simple: '{"id": "${header.CamelGoogleFirestoreResponseDocumentId}"}' Supported Firestore Data Types
The following Java types are automatically converted to Firestore data types:
| Java Type | Firestore Type | Notes |
|---|---|---|
| String | Text data |
| Integer | 64-bit signed integer |
| Floating-point | 64-bit double precision |
| Boolean |
|
| Timestamp | Converted to Firestore Timestamp |
| Timestamp | Native Firestore Timestamp |
| Array | Ordered list, nested types supported |
| Map | Nested document/object |
| Null | Null value |
| Bytes | Binary data (max 1MB) |
| GeoPoint | Latitude/longitude coordinates |
| Reference | Reference to another document |
Output Data Formats
Single Document Operations
For getDocumentById, the response body is:
-
Map<String, Object>- Document data if found -
null- If document does not exist
List/Query Operations
For listDocuments and queryCollection, the response body is:
-
List<Map<String, Object>>- List of documents
Each document Map includes additional metadata fields:
-
_id- The document ID -
_path- The full document path (e.g.,users/user123)
Message Headers
The component uses the following headers:
Producer Headers (Input)
| Header | Type | Description |
|---|---|---|
|
| The operation to perform |
|
| Override the collection name |
|
| The document ID for document operations |
|
| Field name for query filtering |
|
| Operator for query filtering |
|
| Value for query filtering |
|
| Maximum documents to return |
|
| Field to order results by |
|
| Order direction (ASCENDING/DESCENDING) |
|
| Merge data with existing document |
|
| Specific fields to merge; a dotted name such as |
Consumer/Response Headers (Output)
| Header | Type | Description |
|---|---|---|
|
| The document ID |
|
| The full document path |
|
| Document creation time |
|
| Document last update time |
|
| Document read time |
|
| Change type for real-time updates (ADDED, MODIFIED, REMOVED) |