mongodb source MongoDB Source

Provided by: "Apache Software Foundation"

Support Level for this Kamelet is: "Preview"

Consume documents from MongoDB.

If the persistentTailTracking option will be enabled, the consumer will keep track of the last consumed message and on the next restart, the consumption will restart from that message. In case of persistentTailTracking enabled, the tailTrackIncreasingField must be provided (by default it is optional).

If the persistentTailTracking option won’t be enabled, the consumer will consume the whole collection and wait in idle for new documents to consume.

Configuration Options

The following table summarizes the configuration options available for the mongodb-source Kamelet:

Property Name Description Type Default Example

collection *

MongoDB Collection

Sets the name of the MongoDB collection to bind to this endpoint.

string

database *

MongoDB Database

Sets the name of the MongoDB database to target.

string

hosts *

MongoDB Hosts

Comma separated list of MongoDB Host Addresses in host:port format.

string

password

MongoDB Password

User password for accessing MongoDB.

string

persistentTailTracking

MongoDB Persistent Tail Tracking

Enable persistent tail tracking, which is a mechanism to keep track of the last consumed message across system restarts. The next time the system is up, the endpoint will recover the cursor from the point where it last stopped slurping records.

boolean

false

tailTrackIncreasingField

MongoDB Tail Track Increasing Field

Correlation field in the incoming record which is of increasing nature and will be used to position the tailing cursor every time it is generated.

string

username

MongoDB Username

Username for accessing MongoDB.

string

Fields marked with (*) are mandatory.

Usage

This section summarizes how the mongodb-source can be used in various contexts.

Knative Source

The mongodb-source Kamelet can be used as Knative source by binding it to a Knative object.

mongodb-source-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: mongodb-source-binding
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: mongodb-source
    properties:
      collection: "The MongoDB Collection"
      database: "The MongoDB Database"
      hosts: "The MongoDB Hosts"
  sink:
    ref:
      kind: Channel
      apiVersion: messaging.knative.dev/v1
      name: mychannel

Make sure you have Camel K installed into the Kubernetes cluster you’re connected to.

Save the mongodb-source-binding.yaml file into your hard drive, then configure it according to your needs.

You can run the source using the following command:

kubectl apply -f mongodb-source-binding.yaml

Dependencies

The Kamelet needs the following dependencies:

  • camel:kamelet

  • camel:mongodb

  • camel:jackson

Binding to Knative using the Kamel CLI:

The procedure described above can be simplified into a single execution of the kamel bind command:

kamel bind mongodb-source -p "source.collection=The MongoDB Collection" -p "source.database=The MongoDB Database" -p "source.hosts=The MongoDB Hosts" channel:mychannel

This will create the KameletBinding under the hood and apply it to the current namespace in the cluster.

Kafka Source

The mongodb-source Kamelet can be used as Kafka source by binding it to a Kafka topic.

mongodb-source-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: mongodb-source-binding
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1alpha1
      name: mongodb-source
    properties:
      collection: "The MongoDB Collection"
      database: "The MongoDB Database"
      hosts: "The MongoDB Hosts"
  sink:
    ref:
      kind: KafkaTopic
      apiVersion: kafka.strimzi.io/v1beta1
      name: my-topic

Ensure that you’ve installed Strimzi and created a topic named my-topic in the current namespace. Make also sure you have Camel K installed into the Kubernetes cluster you’re connected to.

Save the mongodb-source-binding.yaml file into your hard drive, then configure it according to your needs.

You can run the source using the following command:

kubectl apply -f mongodb-source-binding.yaml

Binding to Kafka using the Kamel CLI:

The procedure described above can be simplified into a single execution of the kamel bind command:

kamel bind mongodb-source -p "source.collection=The MongoDB Collection" -p "source.database=The MongoDB Database" -p "source.hosts=The MongoDB Hosts" kafka.strimzi.io/v1beta1:KafkaTopic:my-topic

This will create the KameletBinding under the hood and apply it to the current namespace in the cluster.

Kamelet source file

Have a look at the following link: