> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Run the Kafka Connector Externally

> Use YAML to configure Kafka ingestion and capture topic metadata, message structure, and event lineage.

![Kafka](https://docs.open-metadata.org/public/images/connectors/kafka.webp)

# Kafka

PROD

In this section, we provide guides and references to use the Kafka connector.
Configure and schedule Kafka metadata and profiler workflows from the OpenMetadata UI:

* [Requirements](#requirements)
* [Metadata Ingestion](#metadata-ingestion)
* [Enable Security](#securing-kafka-connection-with-ssl-in-openmetadata)

## How to Run the Connector Externally

To run the Ingestion via the UI you'll need to use the OpenMetadata Ingestion Container, which comes shipped with
custom Airflow plugins to handle the workflow deployment.

If, instead, you want to manage your workflows externally on your preferred orchestrator, you can check
the following docs to run the Ingestion Framework **anywhere**.

> [card] [External Schedulers](https://docs.open-metadata.org/v2.1.x/deployment/ingestion.md)
>
> Get more information about running the Ingestion Framework Externally

## Requirements

### Python Requirements

Use Python 3.10 or later. Python 3.12 is recommended, because it is what the OpenMetadata 2.0 ingestion images use. To confirm the supported range for your release, check the `Requires-Python` metadata of that release’s `openmetadata-ingestion` package.

To run the Kafka ingestion, you will need to install:

```bash theme={null}
pip3 install "openmetadata-ingestion[kafka]"
```

## Metadata Ingestion

All connectors are defined as JSON Schemas.
[Here](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/entity/services/connections/messaging/kafkaConnection.json)
you can find the structure to create a connection to Kafka.
In order to create and run a Metadata Ingestion workflow, we will follow
the steps to create a YAML configuration able to connect to the source,
process the Entities if needed, and reach the OpenMetadata server.
The workflow is modeled around the following
[JSON Schema](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/metadataIngestion/workflow.json)

### 1. Define the YAML Config

This is a sample config for Kafka:

#### Source Configuration - Source Config

The `sourceConfig` is defined [here](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/metadataIngestion/messagingServiceMetadataPipeline.json):

* **generateSampleData**: Option to turn on or off generating sample data during metadata extraction. It supports boolean values either `true` or `false`.
* **topicFilterPattern**: Note that the `topicFilterPattern` supports regex as include or exclude.
* **markDeletedTopics**: Optional configuration to soft delete topics in OpenMetadata if the source topics are deleted. Also, if the topic is deleted, all the associated entities like sample data, lineage, etc., with that topic will be deleted. It supports boolean values either `true` or `false`.
* **overrideMetadata**: Set the **Override Metadata** toggle to control whether to override the existing metadata in the OpenMetadata server with the metadata fetched from the source. If the toggle is set to true, the metadata fetched from the source will override the existing metadata in the OpenMetadata server. If the toggle is set to false, the metadata fetched from the source will not override the existing metadata in the OpenMetadata server. This is applicable for fields like description, tags, owner, and displayName. It supports boolean values either `true` or `false`.

To send the metadata to OpenMetadata, it needs to be specified as `type: metadata-rest`.

The main property here is `openMetadataServerConfig`, where you can define the host and security provider of your OpenMetadata installation.

* **loggerLevel**: Specify the logger level depending on your needs. If you are troubleshooting an ingestion, use `DEBUG` for more detailed traces.
* **JWT token**: JWT tokens allow clients to authenticate against the OpenMetadata server. See [Enable JWT Tokens](https://docs.open-metadata.org/deployment/security/enable-jwt-tokens) and [JWT Troubleshooting](https://docs.open-metadata.org/deployment/security/jwt-troubleshooting) for more information.
* **storeServiceConnection**: If set to `true` (default), sensitive information is stored encrypted with the Fernet Key or externally if you have configured a [Secrets Manager](https://docs.open-metadata.org/deployment/secrets-manager). If set to `false`, the service is created, but the service connection information is only used by the Ingestion Framework at runtime and is not sent to the OpenMetadata server.
* **SSL configuration**: If you have added SSL to the [OpenMetadata server](https://docs.open-metadata.org/deployment/security/enable-ssl), configure the certificates for ingestion. Set `verifySSL` to `ignore`, or set it to `validate` and provide `sslConfig.caCertificate` with a local path to the server certificate. See [SSL Troubleshooting](https://docs.open-metadata.org/deployment/security/enable-ssl/ssl-troubleshooting) for more information.
* **ingestionPipelineFQN**: Fully qualified name of the ingestion pipeline, used to identify the current ingestion pipeline.

#### Source Configuration

Configure the source type and service name.

#### bootstrapServers

**bootstrapServers**: List of brokers as comma separated values of broker `host` or `host:port`.
Example: `host1:7-807-82,host2:7-807-82`

#### schemaRegistryURL

**schemaRegistryURL**: URL of the Schema Registry used to ingest the schemas of the topics.
If you encounter issues connecting to the Schema Registry, ensure that the protocol is explicitly specified in the Schema Registry URL. For example:

* Use `http://localhost:8081` instead of `localhost:8081`.
  The Schema Registry requires a properly formatted URL, including the protocol (`http://` or `https://`). While this differentiation is expected in the Schema Registry configuration, it may not be immediately apparent.
  **NOTE**: For now, the schema will be the last version found for the schema name `{topic-name}-value`. An [issue](https://github.com/open-metadata/OpenMetadata/issues/8399) to improve how it currently works has been opened.

#### saslUsername

**saslUsername**: SASL username for use with the PLAIN and SASL-SCRAM mechanisms.

#### saslPassword

**saslPassword**: SASL password for use with the PLAIN and SASL-SCRAM mechanisms.

#### saslMechanism

**saslMechanism**: SASL mechanism to use for authentication.
Supported: *GSSAPI, PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, OAUTHBEARER*.
**NOTE**: Despite the name only one mechanism must be configured.

#### basicAuthUserInfo

**basicAuthUserInfo**: Schema Registry Client HTTP credentials in the form of `username:password`.
By default, user info is extracted from the URL if present.

#### consumerConfig

**consumerConfig**: The accepted additional values for the consumer configuration can be found in the following
[link](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md).

#### schemaRegistryConfig

**schemaRegistryConfig**: The accepted additional values for the Schema Registry configuration can be found in the
following [link](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#schemaregistryclient).
**Note:** To ingest the topic schema, `schemaRegistryURL` must be passed.

#### securityProtocol

**securityProtocol**: security.protocol consumer config property. It accepts `PLAINTEXT`,`SASL_PLAINTEXT`, `SASL_SSL`, `SSL`.

#### schemaRegistryTopicSuffixName

**schemaRegistryTopicSuffixName**: Schema Registry Topic Suffix Name. The suffix to be appended to the topic name to get topic schema from registry.

#### schemaRegistrySSL

**schemaRegistrySSL**: Schema Registry SSL Config. Configuration for enabling SSL for the Schema Registry connection.

#### supportsMetadataExtraction

**supportsMetadataExtraction**: Supports Metadata Extraction. `supportsMetadataExtraction` supports boolean value either true or false.

connector\_config.yaml
Copy full code

```yaml theme={null}
source:
  type: kafka
  serviceName: local_kafka
  serviceConnection:
    config:
      type: Kafka
bootstrapServers: localhost:9092  # REQUIRED - Kafka broker addresses
schemaRegistryURL: http://localhost:8081  # Schema Registry URL
saslUsername: username  # SASL authentication username
saslPassword: password  # SASL authentication password
saslMechanism: PLAIN  # SASL mechanism: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, GSSAPI, OAUTHBEARER
basicAuthUserInfo: username:password  # Schema Registry basic auth
consumerConfig:
        # Example consumer configurations:
        # auto.offset.reset: "earliest"
        # max.poll.records: 500
        # session.timeout.ms: 30000
schemaRegistryConfig:
        # Example schema registry configurations:
        # schema.registry.basic.auth.credentials.source: "USER_INFO"
        # schema.registry.ssl.truststore.location: "/path/to/truststore.jks"
securityProtocol: PLAINTEXT  # Security protocol: PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
# schemaRegistryTopicSuffixName: -value
# SSL Configuration for Consumer connections (when securityProtocol is SSL or SASL_SSL)
      # consumerConfigSSL:
      #   caCertificate: "/path/to/ca-cert.pem"
      #   sslCertificate: "/path/to/client-cert.pem"
      #   sslKey: "/path/to/client-key.pem"
# SSL Configuration for Schema Registry connections
      # schemaRegistrySSL:
      #   caCertificate: "/path/to/schema-registry-ca.pem"
      #   sslCertificate: "/path/to/schema-registry-cert.pem"
      #   sslKey: "/path/to/schema-registry-key.pem"
# supportsMetadataExtraction: true
```

```yaml theme={null}
  sourceConfig:
    config:
      type: MessagingMetadata
      topicFilterPattern:
        excludes:
          - _confluent.*
      # includes:
      #   - topic1
      # generateSampleData: true
      # generateSampleData: false # true
      # markDeletedTopics: true # false
      # overrideMetadata:  false # true

```

```yaml theme={null}
sink:
  type: metadata-rest
  config: {}
```

```yaml theme={null}
workflowConfig:
  loggerLevel: INFO  # DEBUG, INFO, WARNING or ERROR
  openMetadataServerConfig:
    hostPort: "http://localhost:8585/api"
    authProvider: openmetadata
    securityConfig:
      jwtToken: "{bot_jwt_token}"
    ## Store the service Connection information
    storeServiceConnection: true  # false
    ## Secrets Manager Configuration
    # secretsManagerProvider: aws, azure or noop
    # secretsManagerLoader: airflow or env
    ## If SSL, fill the following
    # verifySSL: validate  # or ignore
    # sslConfig:
    #   caCertificate: /local/path/to/certificate
# ingestionPipelineFQN: <service name>.<ingestion name> ## e.g., "my_redshift.metadata"
```

## Securing Kafka Connection with SSL in OpenMetadata

To establish secure connections between OpenMetadata and Kafka, in the `YAML` you can provide the CA certificate used for SSL validation by specifying the `caCertificate`. Alternatively, if both client and server require mutual authentication, you'll need to use all three parameters: `ssl key`, `ssl cert`, and `caCertificate`. In this case, `ssl_cert` is used for the client’s SSL certificate, `ssl_key` for the private key associated with the SSL certificate, and `caCertificate` for the CA certificate to validate the server’s certificate.

```yaml theme={null}
      sslConfig:
            caCertificate: "/path/to/ca_certificate"
            sslCertificate: "/path/to/your/ssl_cert"
            sslKey: "/path/to/your/ssl_key"
```

### 2. Run with the CLI

First, we will need to save the YAML file. Afterward, and with all requirements installed, we can run:

```bash theme={null}
metadata ingest -c <path-to-yaml>
```

Note that from connector to connector, this recipe will always be the same. By updating the YAML configuration,
you will be able to extract metadata from different sources.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.