azure cosmosdb sink Azure CosmosDB Sink

Provided by: "Apache Software Foundation"

Support Level for this Kamelet is: "Stable"

Send Data to an Azure CosmosDB instance

In the headers, you can optionally set the itemPartitionKey / ce-itemPartitionKey property to specify the partition key for a specific item.

If you do not set the property in the header, you’ll need to use the static property itemPartitonKey.

There are two different mechanism of authentication SHARED_ACCOUNT_KEY and AZURE_IDENTITY, you could specify with credentialType property. If you’re using SHARED_ACCOUNT_KEY accountKey property will be needed.

In case of AZURE_IDENTITY selection, the DefaultAzureCredential will attempt to authenticate via the following mechanisms in the following order enviroment, Workload Identity, Managed Identity, Azure Developer CLI, IntelliJ, Azure CLI and Azure Powershell.

Configuration Options

The following table summarizes the configuration options available for the azure-cosmosdb-sink Kamelet:

Property Name Description Type Default Example

containerName

Container Name

Required The Azure Cosmos container name.

string

databaseEndpoint

Database Endpoint

Required Sets the Azure Cosmos database endpoint the component will connect to.

string

databaseName

Database Name

Required The Azure Cosmos database name.

string

accountKey

Account Key

The Azure Cosmos account Key.

string

credentialType

Credential Type

Determines the credential strategy to adopt.

Enum values:

* SHARED_ACCOUNT_KEY * AZURE_IDENTITY

string

SHARED_ACCOUNT_KEY

itemPartitionKey

Item 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.

string

Dependencies

At runtime, the azure-cosmosdb-sink Kamelet relies upon the presence of the following dependencies:

  • camel:azure-cosmosdb

  • camel:kamelet

  • camel:jackson

  • camel:core

Camel JBang usage

Prerequisites

  • You’ve installed JBang.

  • You have executed the following command:

jbang app install camel@apache/camel

Supposing you have a file named route.yaml with this content:

- route:
    from:
      uri: "kamelet:timer-source"
      parameters:
        period: 10000
        message: 'test'
      steps:
        - to:
            uri: "kamelet:log-sink"

You can now run it directly through the following command

camel run route.yaml

Camel K Environment Usage

This section describes how you can use the azure-cosmosdb-sink.

Knative sink

You can use the azure-cosmosdb-sink Kamelet as a Knative sink by binding it to a Knative object.

azure-cosmosdb-sink-pipe.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: azure-cosmosdb-sink-pipe
spec:
  source:
    ref:
      kind: Channel
      apiVersion: messaging.knative.dev/v1
      name: mychannel
  sink:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: azure-cosmosdb-sink
    properties:
      containerName: The Container Name
      databaseEndpoint: The Database Endpoint
      databaseName: The Database Name

Prerequisite

You have Camel K installed on the cluster.

Procedure for using the cluster CLI

  1. Save the azure-cosmosdb-sink-pipe.yaml file to your local drive, and then edit it as needed for your configuration.

  2. Run the sink by using the following command:

    kubectl apply -f azure-cosmosdb-sink-pipe.yaml

Procedure for using the Kamel CLI

Configure and run the sink by using the following command:

kamel bind channel:mychannel -p "sink.containerName=The Container Name" -p "sink.databaseEndpoint=The Database Endpoint" -p "sink.databaseName=The Database Name" azure-cosmosdb-sink

This command creates the Kamelet Pipe in the current namespace on the cluster.

Kafka sink

You can use the azure-cosmosdb-sink Kamelet as a Kafka sink by binding it to a Kafka topic.

azure-cosmosdb-sink-pipe.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: azure-cosmosdb-sink-pipe
spec:
  source:
    ref:
      kind: KafkaTopic
      apiVersion: kafka.strimzi.io/v1beta1
      name: my-topic
  sink:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: azure-cosmosdb-sink
    properties:
      containerName: The Container Name
      databaseEndpoint: The Database Endpoint
      databaseName: The Database Name

Prerequisites

  • You’ve installed Strimzi.

  • You’ve created a topic named my-topic in the current namespace.

  • You have Camel K installed on the cluster.

Procedure for using the cluster CLI

  1. Save the azure-cosmosdb-sink-pipe.yaml file to your local drive, and then edit it as needed for your configuration.

  2. Run the sink by using the following command:

    kubectl apply -f azure-cosmosdb-sink-pipe.yaml

Procedure for using the Kamel CLI

Configure and run the sink by using the following command:

kamel bind kafka.strimzi.io/v1beta1:KafkaTopic:my-topic -p "sink.containerName=The Container Name" -p "sink.databaseEndpoint=The Database Endpoint" -p "sink.databaseName=The Database Name" azure-cosmosdb-sink

This command creates the Kamelet Pipe in the current namespace on the cluster.