Skip to content

Apache Kafka Channel Binding v0.4.0

The Apache Kafka channel binding object allows you to define Kafka-specific information for an AsyncAPI channel. This binding is essential for configuring Kafka topics, including the number of partitions, replicas, and other topic-level settings.

Overview

The Kafka channel binding provides a detailed description of a Kafka topic, enabling you to manage its configuration directly within your AsyncAPI specification. This ensures that your applications and other stakeholders have a clear and consistent understanding of the topic's setup.

Channel Properties

PropertyTypeRequiredDescription
topicstringNoThe name of the Kafka topic. If not specified, the channel name will be used.
partitionsintegerNoThe number of partitions for the topic. Must be a positive integer.
replicasintegerNoThe number of replicas for the topic. Must be a positive integer.
topicConfigurationobjectNoAn object containing advanced topic configuration properties.
bindingVersionstringNoThe version of the Kafka channel binding. Defaults to latest.

topicConfiguration Object

The topicConfiguration object allows you to specify advanced settings for the Kafka topic.

PropertyTypeDescription
cleanup.policyarray[string]The topic's cleanup policy. Can be compact or delete. See Kafka documentation.
retention.msintegerThe retention period for messages in milliseconds. See Kafka documentation.
retention.bytesintegerThe maximum size of the log segment. See Kafka documentation.
delete.retention.msintegerThe retention period for deleted records. See Kafka documentation.
max.message.bytesintegerThe maximum size of a message. See Kafka documentation.

Examples

Basic Topic Configuration

This example defines a Kafka topic with a specific number of partitions and replicas.

yaml
channels:
  user-signup:
    bindings:
      kafka:
        topic: user-signup-topic
        partitions: 10
        replicas: 3
        bindingVersion: '0.4.0'

Advanced Topic Configuration

This example demonstrates how to set advanced topic properties, such as cleanup policy and retention settings.

yaml
channels:
  order-events:
    bindings:
      kafka:
        topic: order-events-topic
        partitions: 20
        replicas: 3
        topicConfiguration:
          cleanup.policy: ["compact", "delete"]
          retention.ms: 86400000
          max.message.bytes: 1048576
        bindingVersion: '0.4.0'

Use Cases

High-Throughput Data Streaming

Configure a topic with a high number of partitions to handle a large volume of incoming data from multiple producers.

yaml
channels:
  iot-sensor-data:
    bindings:
      kafka:
        topic: iot-data
        partitions: 50
        replicas: 3
        bindingVersion: '0.4.0'

Event Sourcing

Use a compacted topic to store the full history of events for a specific entity, ensuring that only the latest state is retained.

yaml
channels:
  customer-profile-events:
    bindings:
      kafka:
        topic: customer-profiles
        partitions: 5
        replicas: 3
        topicConfiguration:
          cleanup.policy: ["compact"]
        bindingVersion: '0.4.0'

Log Aggregation

Configure a topic with a specific retention period to store logs for a defined amount of time.

yaml
channels:
  application-logs:
    bindings:
      kafka:
        topic: app-logs
        partitions: 10
        replicas: 2
        topicConfiguration:
          retention.ms: 604800000 # 7 days
        bindingVersion: '0.4.0'