ArangoDb
Since Camel 3.5
Only producer is supported
The ArangoDb component is client for ArangoDb that uses the arango java driver to perform queries on collections and graphs in the ArangoDb database.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-arangodb</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> 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 ArangoDb component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The shared configuration of the endpoints. Each endpoint starts from a copy of it, and the options of the endpoint URI replace its values. | ArangoDbConfiguration | ||
The name of the document collection for the operations SAVE_DOCUMENT, FIND_DOCUMENT_BY_KEY, UPDATE_DOCUMENT and DELETE_DOCUMENT. The producer does not create the collection. | String | ||
The name of the edge collection of the graph for the operations SAVE_EDGE, FIND_EDGE_BY_KEY, UPDATE_EDGE and DELETE_EDGE. The graph option must be set as well. | String | ||
The name of the named graph for the vertex and edge operations, such as SAVE_VERTEX and SAVE_EDGE. Use it with vertexCollection for the vertex operations, and with edgeCollection for the edge operations. | String | ||
The host name or IP address of the ArangoDB server. Must be set together with port, unless the arangoDB option sets a client, in which case it is not used. | 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. Required: the producer fails to start without it, and no header replaces it. AQL_QUERY needs only the database, not a collection or a graph. Enum values:
| ArangoDbOperation | ||
The port of the ArangoDB server, for example 8529, the default port of ArangoDB. Must be set together with host, unless the arangoDB option sets a client, in which case it is not used. | int | ||
The name of the vertex collection of the graph for the operations SAVE_VERTEX, FIND_VERTEX_BY_KEY, UPDATE_VERTEX and DELETE_VERTEX. The graph option must be set as well. | String | ||
Autowired To use a custom com.arangodb.ArangoDB client for all the endpoints of the component. When it is set or autowired, the host, port, user, password and vertx options are not used, and the endpoints do not shut the client down. | ArangoDB | ||
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 | |
Autowired To use a custom io.vertx.core.Vertx instance for the HTTP connections of the ArangoDB clients that the endpoints create. If not set, the ArangoDB driver creates its own Vert.x instance. Not used when the arangoDB option sets a client. | Vertx | ||
The password of the user that the ArangoDB client logs in with. Only used when user is set as well. Not used when the arangoDB option sets a client. | String | ||
The name of the user that the ArangoDB client logs in with. Only used when password is set as well. If either is not set, the ArangoDB driver logs in as the user root with no password. Not used when the arangoDB option sets a client. | String |
Endpoint Options
The ArangoDb endpoint is configured using URI syntax:
arangodb:database
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The name of the document collection for the operations SAVE_DOCUMENT, FIND_DOCUMENT_BY_KEY, UPDATE_DOCUMENT and DELETE_DOCUMENT. The producer does not create the collection. | String | ||
The name of the edge collection of the graph for the operations SAVE_EDGE, FIND_EDGE_BY_KEY, UPDATE_EDGE and DELETE_EDGE. The graph option must be set as well. | String | ||
The name of the named graph for the vertex and edge operations, such as SAVE_VERTEX and SAVE_EDGE. Use it with vertexCollection for the vertex operations, and with edgeCollection for the edge operations. | String | ||
The host name or IP address of the ArangoDB server. Must be set together with port, unless the arangoDB option sets a client, in which case it is not used. | String | ||
The operation that the producer performs. Required: the producer fails to start without it, and no header replaces it. AQL_QUERY needs only the database, not a collection or a graph. Enum values:
| ArangoDbOperation | ||
The port of the ArangoDB server, for example 8529, the default port of ArangoDB. Must be set together with host, unless the arangoDB option sets a client, in which case it is not used. | int | ||
The name of the vertex collection of the graph for the operations SAVE_VERTEX, FIND_VERTEX_BY_KEY, UPDATE_VERTEX and DELETE_VERTEX. The graph option must be set as well. | 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 | |
To use a custom com.arangodb.ArangoDB client. When it is set, or set on the component, the host, port, user, password and vertx options are not used, and the endpoint does not shut the client down. | ArangoDB | ||
To use a custom io.vertx.core.Vertx instance for the HTTP connections of the ArangoDB client that the endpoint creates. If not set, the ArangoDB driver creates its own Vert.x instance. Not used when the arangoDB option sets a client. | Vertx | ||
The password of the user that the ArangoDB client logs in with. Only used when user is set as well. Not used when the arangoDB option sets a client. | String | ||
The name of the user that the ArangoDB client logs in with. Only used when password is set as well. If either is not set, the ArangoDB driver logs in as the user root with no password. Not used when the arangoDB option sets a client. | String |
Message Headers
The ArangoDb component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelArangoDbMultiUpdate (producer) Constant: | Whether UPDATE_DOCUMENT updates several documents. If true, the body must be a Collection of documents that each have their _key, and the CamelArangoDbKey header is not used. | false | Boolean |
CamelArangoDbMultiInsert (producer) Constant: | Whether SAVE_DOCUMENT saves several documents. If true, the body must be a Collection of documents. A Collection body is saved as several documents even when this header is not set. | false | Boolean |
CamelArangoDbMultiDelete (producer) Constant: | Whether DELETE_DOCUMENT deletes several documents. If true, the body must be a Collection of the keys of the documents. If false, the body is the key of one document. | false | Boolean |
| Constant: | The key, as a String, of the document, vertex or edge that UPDATE_DOCUMENT, UPDATE_VERTEX and UPDATE_EDGE update. The find and delete operations take the key from the body instead. | String | |
CamelArangoDbResultClassType (producer) Constant: | The java.lang.Class that FIND_DOCUMENT_BY_KEY, FIND_VERTEX_BY_KEY, FIND_EDGE_BY_KEY and AQL_QUERY convert each result to. A class name as text is not accepted. If not set, BaseEdgeDocument is used for FIND_EDGE_BY_KEY and BaseDocument for the other operations. | BaseDocument.class or BaseEdgeDocument.class | Class |
CamelArangoDbAqlQuery (producer) Constant: | The AQL query that AQL_QUERY runs. If not set, the body is the query. | String | |
CamelArangoDbAqlParameters (producer) Constant: | The bind parameters of the AQL query of AQL_QUERY, as a Map from the name of each bind parameter to its value, for example foo for foo in the query. | Map | |
CamelArangoDbAqlOptions (advanced) Constant: | The com.arangodb.model.AqlQueryOptions of the AQL query of AQL_QUERY, such as its batch size. If not set, the query runs with the default options. | AqlQueryOptions |
Message Body
The message body at each side of the ArangoDb 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 |
|---|---|---|
Producer input |
| By the operation: the document to save or update as a Map or a POJO (a Collection of them saves several, with or without the CamelArangoDbMultiInsert header, and a List of them with the CamelArangoDbMultiUpdate header updates several), the key as text to find or delete (a List of keys with CamelArangoDbMultiDelete), and the AQL query as text unless the CamelArangoDbAqlQuery header has it. JSON text, bytes or a stream is not a document: unmarshal it to a Map first. The key of an update is the CamelArangoDbKey header.
|
Producer output |
| By the operation, which must be set (the producer fails to start without it): the result entity of the ArangoDB driver (DocumentCreateEntity, DocumentUpdateEntity, DocumentDeleteEntity, or a MultiDocumentEntity for the multi headers and a Collection saved) for the document writes; the document found as a BaseDocument (or BaseEdgeDocument), or of the class in the CamelArangoDbResultClassType header, or null when there is none; a List of the AQL results, empty for a query that returns nothing; and true for a delete of a vertex or edge.
|
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.
The operation option must be set, on the endpoint or on the component configuration: there is no default operation, and a route that sends to an arangodb endpoint without it fails to start.
Examples
Producer Examples
Save document on a collection
-
Java
-
XML
-
YAML
from("direct:insert")
.to("arangodb:testDb?documentCollection=collection&operation=SAVE_DOCUMENT"); <route>
<from uri="direct:insert"/>
<to uri="arangodb:testDb?documentCollection=collection&operation=SAVE_DOCUMENT"/>
</route> - route:
from:
uri: direct:insert
steps:
- to:
uri: arangodb:testDb
parameters:
documentCollection: collection
operation: SAVE_DOCUMENT And you can set as body a BaseDocument class
BaseDocument myObject = new BaseDocument();
myObject.addAttribute("a", "Foo");
myObject.addAttribute("b", 42); A Collection body, such as a List of documents, saves each of them as a document, with or without the CamelArangoDbMultiInsert header, and the body after the operation is a MultiDocumentEntity.
Query a collection
-
Java
-
XML
-
YAML
from("direct:query")
.to("arangodb:testDb?operation=AQL_QUERY"); <route>
<from uri="direct:query"/>
<to uri="arangodb:testDb?operation=AQL_QUERY"/>
</route> - route:
from:
uri: direct:query
steps:
- to:
uri: arangodb:testDb
parameters:
operation: AQL_QUERY And you can invoke an AQL Query in this way
String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.value == @value";
Map<String, Object> bindVars = new MapBuilder().put("value", "hello")
.get();
Exchange result = template.request("direct:query", exchange -> {
exchange.getMessage().setHeader(AQL_QUERY, query);
exchange.getMessage().setHeader(AQL_QUERY_BIND_PARAMETERS, bindVars);
});