Skip to content

Commit

Permalink
CAMEL-15655: Add Camel Azure CosmosDB Starter (#326)
Browse files Browse the repository at this point in the history
* CAMEL-15655: Add Camel Azure CosmosDB Starter

* Add docs
  • Loading branch information
omarsmak committed May 4, 2021
1 parent c8d53bf commit ed6bd34
Show file tree
Hide file tree
Showing 18 changed files with 1,223 additions and 0 deletions.
Expand Up @@ -40,6 +40,7 @@ aws2-sns
aws2-sqs
aws2-sts
aws2-translate
azure-cosmosdb
azure-eventhubs
azure-storage-blob
azure-storage-datalake
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions components-starter/README.adoc
Expand Up @@ -93,6 +93,8 @@ Number of Camel components: 329 in 265 JAR artifacts (1 deprecated)

| xref:latest@components::aws-secrets-manager-component.adoc[AWS Secrets Manager] | camel-aws-secrets-manager-starter | Preview | 3.9 | Manage AWS Secrets Manager services using AWS SDK version 2.x.

| xref:latest@components::azure-cosmosdb-component.adoc[Azure CosmosDB] | camel-azure-cosmosdb-starter | Preview | 3.10 | Azure Cosmos DB is Microsofts globally distributed, multi-model database service for operational and analytics workloads. It offers multi-mastering feature by automatically scaling throughput, compute, and storage. This component interacts with Azure CosmosDB through Azure SQL API

| xref:latest@components::azure-eventhubs-component.adoc[Azure Event Hubs] | camel-azure-eventhubs-starter | Stable | 3.5 | The azure-eventhubs component that integrates Azure Event Hubs using AMQP protocol. Azure EventHubs is a highly scalable publish-subscribe service that can ingest millions of events per second and stream them to multiple consumers.

| xref:latest@components::azure-storage-blob-component.adoc[Azure Storage Blob Service] | camel-azure-storage-blob-starter | Stable | 3.3 | Store and retrieve blobs from Azure Storage Blob Service using SDK v12.
Expand Down
48 changes: 48 additions & 0 deletions components-starter/camel-azure-cosmosdb-starter/pom.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>components-starter</artifactId>
<version>3.10.0-SNAPSHOT</version>
</parent>
<artifactId>camel-azure-cosmosdb-starter</artifactId>
<packaging>jar</packaging>
<!-- <name>Camel SB Starters :: Name Here</name>-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-azure-cosmosdb</artifactId>
<version>${camel-version}</version>
</dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-core-starter</artifactId>
</dependency>
<!--END OF GENERATED CODE-->
</dependencies>
</project>
@@ -0,0 +1,60 @@
// spring-boot-auto-configure options: START
:page-partial:
:doctitle: Camel Spring Boot Starter for azure-cosmosdb

== Spring Boot Auto-Configuration

When using azure-cosmosdb with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-azure-cosmosdb-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 30 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.component.azure-cosmosdb.account-key* | Sets either a master or readonly key used to perform authentication for accessing resource. | | String
| *camel.component.azure-cosmosdb.autowired-enabled* | 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
| *camel.component.azure-cosmosdb.bridge-error-handler* | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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
| *camel.component.azure-cosmosdb.change-feed-processor-options* | Sets the ChangeFeedProcessorOptions to be used. Unless specifically set the default values that will be used are: maximum items per page or FeedResponse: 100 lease renew interval: 17 seconds lease acquire interval: 13 seconds lease expiration interval: 60 seconds feed poll delay: 5 seconds maximum scale count: unlimited. The option is a com.azure.cosmos.models.ChangeFeedProcessorOptions type. | | ChangeFeedProcessorOptions
| *camel.component.azure-cosmosdb.client-telemetry-enabled* | Sets the flag to enable client telemetry which will periodically collect database operations aggregation statistics, system information like cpu/memory and send it to cosmos monitoring service, which will be helpful during debugging. DEFAULT value is false indicating this is opt in feature, by default no telemetry collection. | false | Boolean
| *camel.component.azure-cosmosdb.configuration* | The component configurations. The option is a org.apache.camel.component.azure.cosmosdb.CosmosDbConfiguration type. | | CosmosDbConfiguration
| *camel.component.azure-cosmosdb.connection-sharing-across-clients-enabled* | Enables connections sharing across multiple Cosmos Clients. The default is false. When you have multiple instances of Cosmos Client in the same JVM interacting to multiple Cosmos accounts, enabling this allows connection sharing in Direct mode if possible between instances of Cosmos Client. Please note, when setting this option, the connection configuration (e.g., socket timeout config, idle timeout config) of the first instantiated client will be used for all other client instances. | false | Boolean
| *camel.component.azure-cosmosdb.consistency-level* | Sets the consistency levels supported for Azure Cosmos DB client operations in the Azure Cosmos DB service. The requested ConsistencyLevel must match or be weaker than that provisioned for the database account. Consistency levels by order of strength are STRONG, BOUNDED_STALENESS, SESSION and EVENTUAL. Refer to consistency level documentation for additional details: \https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels | | ConsistencyLevel
| *camel.component.azure-cosmosdb.container-partition-key-path* | Sets the container partition key path. | | String
| *camel.component.azure-cosmosdb.content-response-on-write-enabled* | Sets the boolean to only return the headers and status code in Cosmos DB response in case of Create, Update and Delete operations on CosmosItem. In Consumer, it is enabled by default because of the ChangeFeed in the consumer that needs this flag to be enabled and thus is shouldn't be overridden. In Producer, it advised to disable it since it reduces the network overhead | true | Boolean
| *camel.component.azure-cosmosdb.cosmos-async-client* | Inject an external CosmosAsyncClient into the component which provides a client-side logical representation of the Azure Cosmos DB service. This asynchronous client is used to configure and execute requests against the service. The option is a com.azure.cosmos.CosmosAsyncClient type. | | CosmosAsyncClient
| *camel.component.azure-cosmosdb.create-container-if-not-exists* | Sets if the component should create Cosmos container automatically in case it doesn't exist in Cosmos database | false | Boolean
| *camel.component.azure-cosmosdb.create-database-if-not-exists* | Sets if the component should create Cosmos database automatically in case it doesn't exist in Cosmos account | false | Boolean
| *camel.component.azure-cosmosdb.create-lease-container-if-not-exists* | Sets if the component should create Cosmos lease container for the consumer automatically in case it doesn't exist in Cosmos database | false | Boolean
| *camel.component.azure-cosmosdb.create-lease-database-if-not-exists* | Sets if the component should create Cosmos lease database for the consumer automatically in case it doesn't exist in Cosmos account | false | Boolean
| *camel.component.azure-cosmosdb.database-endpoint* | Sets the Azure Cosmos database endpoint the component will connect to. | | String
| *camel.component.azure-cosmosdb.enabled* | Whether to enable auto configuration of the azure-cosmosdb component. This is enabled by default. | | Boolean
| *camel.component.azure-cosmosdb.host-name* | Sets the hostname. The host: a host is an application instance that uses the change feed processor to listen for changes. Multiple instances with the same lease configuration can run in parallel, but each instance should have a different instance name. If not specified, this will be a generated random hostname. | | String
| *camel.component.azure-cosmosdb.item-id* | Sets the itemId in case needed for operation on item like delete, replace | | String
| *camel.component.azure-cosmosdb.item-partition-key* | Sets partition key. Represents a partition key value in the Azure Cosmos DB database service. A partition key identifies the partition where the item is stored in. The option is a com.azure.cosmos.models.PartitionKey type. | | PartitionKey
| *camel.component.azure-cosmosdb.lazy-start-producer* | 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
| *camel.component.azure-cosmosdb.lease-container-name* | Sets the lease container which acts as a state storage and coordinates processing the change feed across multiple workers. The lease container can be stored in the same account as the monitored container or in a separate account. It will be auto created if createLeaseContainerIfNotExists is set to true. | camel-lease | String
| *camel.component.azure-cosmosdb.lease-database-name* | Sets the lease database where the leaseContainerName will be stored. If it is not specified, this component will store the lease container in the same database that is specified in databaseName. It will be auto created if createLeaseDatabaseIfNotExists is set to true. | | String
| *camel.component.azure-cosmosdb.multiple-write-regions-enabled* | Sets the flag to enable writes on any regions for geo-replicated database accounts in the Azure Cosmos DB service. When the value of this property is true, the SDK will direct write operations to available writable regions of geo-replicated database account. Writable regions are ordered by PreferredRegions property. Setting the property value to true has no effect until EnableMultipleWriteRegions in DatabaseAccount is also set to true. DEFAULT value is true indicating that writes are directed to available writable regions of geo-replicated database account. | true | Boolean
| *camel.component.azure-cosmosdb.operation* | The CosmosDB operation that can be used with this component on the producer. | | CosmosDbOperationsDefinition
| *camel.component.azure-cosmosdb.preferred-regions* | Sets the preferred regions for geo-replicated database accounts. For example, East US as the preferred region. When EnableEndpointDiscovery is true and PreferredRegions is non-empty, the SDK will prefer to use the regions in the container in the order they are specified to perform operations. | | List
| *camel.component.azure-cosmosdb.query* | An SQL query to execute on a given resources. To learn more about Cosmos SQL API, check this link {link \https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-getting-started} | | String
| *camel.component.azure-cosmosdb.query-request-options* | Set additional QueryRequestOptions that can be used with queryItems, queryContainers, queryDatabases, listDatabases, listItems, listContainers operations. The option is a com.azure.cosmos.models.CosmosQueryRequestOptions type. | | CosmosQueryRequestOptions
| *camel.component.azure-cosmosdb.read-requests-fallback-enabled* | Sets whether to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. DEFAULT value is true. If this property is not set, the default is true for all Consistency Levels other than Bounded Staleness, The default is false for Bounded Staleness. 1. endpointDiscoveryEnabled is true 2. the Azure Cosmos DB account has more than one region | true | Boolean
| *camel.component.azure-cosmosdb.throughput-properties* | Sets throughput of the resources in the Azure Cosmos DB service. The option is a com.azure.cosmos.models.ThroughputProperties type. | | ThroughputProperties
|===


// spring-boot-auto-configure options: END
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.azure.cosmosdb.springboot;

import javax.annotation.Generated;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.component.azure.cosmosdb.CosmosDbComponent;
import org.apache.camel.spi.ComponentCustomizer;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.apache.camel.spring.boot.ComponentConfigurationProperties;
import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
import org.apache.camel.spring.boot.util.ConditionalOnHierarchicalProperties;
import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
* Generated by camel-package-maven-plugin - do not edit this file!
*/
@Generated("org.apache.camel.springboot.maven.SpringBootAutoConfigurationMojo")
@Configuration(proxyBeanMethods = false)
@Conditional(ConditionalOnCamelContextAndAutoConfigurationBeans.class)
@EnableConfigurationProperties({ComponentConfigurationProperties.class,CosmosDbComponentConfiguration.class})
@ConditionalOnHierarchicalProperties({"camel.component", "camel.component.azure-cosmosdb"})
@AutoConfigureAfter({CamelAutoConfiguration.class, CosmosDbComponentConverter.class})
public class CosmosDbComponentAutoConfiguration {

@Autowired
private ApplicationContext applicationContext;
private final CamelContext camelContext;
@Autowired
private CosmosDbComponentConfiguration configuration;

public CosmosDbComponentAutoConfiguration(
org.apache.camel.CamelContext camelContext) {
this.camelContext = camelContext;
}

@Lazy
@Bean
public ComponentCustomizer configureCosmosDbComponent() {
return new ComponentCustomizer() {
@Override
public void configure(String name, Component target) {
CamelPropertiesHelper.copyProperties(camelContext, configuration, target);
}
@Override
public boolean isEnabled(String name, Component target) {
return HierarchicalPropertiesEvaluator.evaluate(
applicationContext,
"camel.component.customizer",
"camel.component.azure-cosmosdb.customizer")
&& target instanceof CosmosDbComponent;
}
};
}
}

0 comments on commit ed6bd34

Please sign in to comment.