Get started with Aiven for Apache Kafka®
Start using Aiven for Apache Kafka® by setting up and configuring a service, connecting to it, and managing your data.
Prerequisites
Before you begin, ensure you have access to the following tools:
Create an Aiven for Apache Kafka® service
You can create your Aiven for Apache Kafka service using the Aiven Console, the Aiven CLI, or automate the process with Terraform.
- Console
- Terraform
- CLI
-
From your project, in the Services page, click Create service.
-
From the Select service page, click Apache Kafka®.
-
Select the cloud provider and region to host your service on.
noteThe pricing for the same service can vary between different providers and regions. The service summary shows you the pricing for your selected options.
-
Select a service plan.
noteThis determines the number of servers and the memory, CPU, and disk resources allocated to your service. See Plans & Pricing.
-
Optional: Add disk storage.
-
Enter a name for your service.
importantYou cannot change the name after you create the service.
-
Optional: Add tags.
-
Click Create service.
The Overview page of the service opens. It shows the connection parameters for your service, its current status, and the configuration options.
The status of the service is Rebuilding during its creation. When the status becomes Running, you can start using the service. This typically takes couple of minutes and can vary between cloud providers and regions.
-
Create a
sample.tf
file for theaiven
provider configuration and theaiven_kafka
resource.variable "aiven_token" {
type = string
}
variable "aiven_project_name" {
type = string
}
terraform {
required_providers {
aiven = {
source = "aiven/aiven"
version = ">=4.0.0, <5.0.0"
}
}
}
provider "aiven" {
api_token = var.aiven_token
}
resource "aiven_kafka" "kafka" {
project = var.aiven_project_name
cloud_name = "google-europe-west1"
plan = "startup-2"
service_name = "my-kafka"
maintenance_window_dow = "friday"
maintenance_window_time = "23:00:00"
kafka_user_config {
kafka_version = "3.7"
}
}
output "kafka_service_host" {
value = aiven_kafka.kafka.service_host
}
output "kafka_service_port" {
value = aiven_kafka.kafka.service_port
}
output "kafka_service_username" {
value = aiven_kafka.kafka.service_username
}
output "kafka_service_password" {
value = aiven_kafka.kafka.service_password
sensitive = true
} -
Create a
terraform.tfvars
file to assign values to your declared variables.aiven_token = "AIVEN_TOKEN"
aiven_project_name = "PROJECT_NAME" -
Run the following commands to initialize and apply the configuration:
terraform init
terraform plan
terraform apply --auto-approve -
Store the Terraform outputs in environment variables to use them when connecting:
KAFKA_HOST="$(terraform output -raw kafka_service_host)"
KAFKA_PORT="$(terraform output -raw kafka_service_port)"
KAFKA_USER="$(terraform output -raw kafka_service_username)"
KAFKA_PASSWORD="$(terraform output -raw kafka_service_password)"
Open your terminal and run the following command:
avn service create SERVICE_NAME \
--service-type kafka \
--cloud CLOUD_REGION \
--plan SERVICE_PLAN \
-c kafka_connect=true \
-c tiered_storage.enabled=true \
--disk-space-gib STORAGE_SIZE_GIB
Parameters:
SERVICE_NAME
: Name for your Aiven for Apache Kafka service.CLOUD_REGION
: Cloud region for deployment. For example,google-europe-west3
.SERVICE_PLAN
: Aiven subscription plan. For example,business-4
.kafka_connect
: Enables Kafka Connect. Usetrue
to enable.tiered_storage.enabled
: Enables tiered storage. Usetrue
to enable.STORAGE_SIZE_GIB
: Disk space in GiB. For example,600
.
Create an Apache Kafka® topic
Once your service is created, you can add topics for organizing and managing your messages.
- Console
- Terraform
- CLI
- Log in to the Aiven Console and select the Aiven for Apache Kafka® service.
- Click Topics in the sidebar.
- Click Create topic and enter a name for the topic.
- If required, set the advanced configuration option to Yes.
- Set properties like replication factor, number of partitions, and other settings. These can be changed later.
- Click Create topic.
-
Add the following Terraform configuration to your
.tf
file:resource "aiven_kafka_topic" "example_topic" {
project = data.aiven_project.example_project.project
service_name = aiven_kafka.example_kafka.service_name
topic_name = "example-topic"
partitions = 5
replication = 3
termination_protection = true
config {
flush_ms = 10
cleanup_policy = "compact,delete"
}
timeouts {
create = "1m"
read = "5m"
}
}Parameters:
project
: Name of the project.service_name
: Name of the Aiven for Apache Kafka service.topic_name
: Name of the Apache Kafka topic.partitions
: Number of partitions for the topic.replication
: Replication factor for the topic.termination_protection
: Enables or disables deletion protection for the topic.config
: Additional Apache Kafka settings, such as flush interval and cleanup policy. For a list of supported configurations, see Aiven for Apache Kafka topic configurations.timeouts
: Optional timeouts for creating and reading the topic.
-
Run
terraform apply
to create the topic with the defined configurations.
-
Determine the topic specifications, including the number of partitions, replication factor, and other settings.
-
Run the following command to create the
exampleTopic
topic:avn service topic-create \
--project demo-kafka-project \
--service-name demo-kafka-service \
--topic exampleTopic \
--partitions 2 \
--replication 2Parameters:
avn service topic-create
: Creates a topic.--project demo-kafka-project
: The name of the project in Aiven.--service-name demo-kafka-service
: The name of the Aiven for Apache Kafka® service.--topic exampleTopic
: The name of the topic to create.--partitions 2
: The number of partitions for the topic.--replication 2
: The replication factor for the topic.
Connect to your Aiven for Apache Kafka service
You can connect to your Aiven for Apache Kafka service to interact with Apache Kafka topics, allowing you to produce and consume messages. Use Quick connect in the Aiven Console to guide the process.
-
Log in to the Aiven Console, select your project, and the Aiven for Apache Kafka service.
-
On the Overview page, click Quick connect.
-
In the Connect window, select your preferred tool or language from the drop-down list.
-
Follow the connection instructions. You may need to download:
- CA certificate: Required for secure communication.
- Access certificate and Access key: Needed for client certificate authentication.
-
Select your authentication method based on your environment:
- Client certificate: Provides secure communication using SSL/TLS certificates. For information on downloading CA certificates, see TLS/SSL certificates.
- SASL: Provides authentication using Simple Authentication and Security Layer (SASL).
-
Click Done.
Produce and consume messages
After connecting, use your preferred Apache Kafka client to produce and consume messages.
Produce messages
To produce messages using Python:
from kafka import KafkaProducer
# Set up the Kafka producer
producer = KafkaProducer(
bootstrap_servers='your-kafka-host:port', # Replace with your Kafka service host and port
security_protocol='SSL',
ssl_cafile='path/to/ca.pem',
ssl_certfile='path/to/service.cert',
ssl_keyfile='path/to/service.key'
)
# Send a test message to a topic
producer.send('your-topic', b'This is a test message')
producer.flush()
producer.close()
Consume messages
To consume messages using Python:
from kafka import KafkaConsumer
# Set up the Kafka consumer
consumer = KafkaConsumer(
'your-topic', # Replace with your topic name
bootstrap_servers='your-kafka-host:port', # Replace with your Kafka service host and port
security_protocol='SSL',
ssl_cafile='path/to/ca.pem',
ssl_certfile='path/to/service.cert',
ssl_keyfile='path/to/service.key',
auto_offset_reset='earliest'
)
# Consume and print messages from the topic
for message in consumer:
print(f"Received message: {message.value}")
Integrate Aiven for Apache Kafka with external systems
Aiven for Apache Kafka supports a wide range of integrations, allowing you to connect with external systems. Key integration options include:
- Apache Kafka Connect: Integrates Apache Kafka with external systems for data import, export, and building complex data pipelines. Learn more about configuring Kafka Connect.
- Apache Kafka MirrorMaker: Enables cross-cluster replication to replicate data between Apache Kafka clusters for disaster recovery or geographical distribution.
- Prometheus and Datadog: Monitors and manages Apache Kafka metrics to help maintain the health and performance of your Apache Kafka services.
- Elasticsearch and OpenSearch: Stores Apache Kafka logs and performs advanced search and analytics, making it easier to query and analyze your Apache Kafka data.
- Apache Flink® and Apache Kafka® Streams: Processes and analyzes real-time data streams from Apache Kafka for complex event processing and stream transformations.
You can configure these integrations in the Aiven Console. In your project, click Integration endpoints to efficient connect your Apache Kafka service with other platforms and tools.
Configure Aiven for Apache Kafka® Connect
Aiven for Apache Kafka® Connect integrates your Apache Kafka service with various data sources and sinks, enabling you to build and manage data pipelines.
Make sure your Aiven for Apache Kafka service is running on a business or premium plan.
You can deploy Aiven for Apache Kafka Connect in two ways:
- For a cost-effective setup, enable Apache Kafka Connect on the same node as your Aiven for Apache Kafka service. Suitable only for testing or hobbyist workloads where cost minimization is a priority.
- For better performance and stability, deploy a dedicated Aiven for Apache Kafka Connect service. Recommended for production deployments and larger workloads requiring reliability.
Enable Karapace
Karapace, an Aiven-built open-source schema registry for Apache Kafka®, provides schema management and REST APIs for interacting with Aiven for Apache Kafka.
- Enable Karapace schema registry and REST APIs in your Kafka service.
- Use Karapace to register, update, and version control your schemas.
Learn more about the Karapace schema registry.
View topic catalog Early availability
The Aiven for Apache Kafka topic catalog provides a centralized interface to view, request, and manage topics across projects. It simplifies topic management and ensures governance within your Aiven for Apache Kafka infrastructure.
- Log in to the Aiven Console.
- Click Tools.
- Select Apache Kafka topic catalog.
Learn more about the Aiven for Apache Kafka® topic catalog.
Enable governance Limited availability
Governance in Aiven for Apache Kafka provides a secure and efficient way to manage your Apache Kafka clusters. It centralizes control through policies and roles, ensuring compliance and enforcing standards across your Aiven for Apache Kafka environments.
You need super admin permissions to enable governance.
- Access the Aiven Console and click Admin.
- On the organization page, click Apache Kafka governance.
- Click Enable governance.
Learn more about the Aiven for Apache Kafka® governance overview.
Related pages
- Explore examples project for code samples.
- Use the sample data generator project to create test data.
- Learn about the Karapace Schema Registry for managing schemas and interacting with Apache Kafka.
- Use the Apache Kafka REST API to programmatically access your Apache Kafka service, produce and consume messages, and manage schemas.