tencent cloud

TDMQ for CKafka

Release Notes and Announcements
Release Notes
Broker Release Notes
Announcement
Product Introduction
Introduction and Selection of the TDMQ Product Series
What Is TDMQ for CKafka
Strengths
Scenarios
Technology Architecture
Product Series Introduction
Apache Kafka Version Support Description
Comparison with Apache Kafka
High Availability
Use Limits
Regions and AZs
Related Cloud Services
Billing
Billing Overview
Pricing
Billing Example
Changing from Postpaid by Hour to Monthly Subscription
Renewal
Viewing Consumption Details
Overdue Payments
Refund
Getting Started
Guide for Getting Started
Preparations
VPC Network Access
Public Domain Name Access
User Guide
Usage Process Guide
Configuring Account Permission
Creating Instance
Configuring Topic
Connecting Instance
Managing Messages
Managing Consumer Group
Managing Instance
Changing Instance Specification
Configuring Traffic Throttling
Configuring Elastic Scaling Policy
Configuring Advanced Features
Viewing Monitoring Data and Configuring Alarm Rules
Synchronizing Data Using CKafka Connector
Use Cases
Cluster Resource Assessment
Client Practical Tutorial
Log Integration
Open-Source Ecosystem Integration
Replacing Supporting Route (Old)
Migration Guide
Migration Solution Overview
Migrating Cluster Using Open-Source Tool
Troubleshooting
Topics
Clients
Messages
​​API Reference
History
Introduction
API Category
Making API Requests
Other APIs
ACL APIs
Instance APIs
Routing APIs
DataHub APIs
Topic APIs
Data Types
Error Codes
SDK Reference
SDK Overview
Java SDK
Python SDK
Go SDK
PHP SDK
C++ SDK
Node.js SDK
SDK for Connector
Security and Compliance
Permission Management
Network Security
Deletion Protection
Event Record
CloudAudit
FAQs
Instances
Topics
Consumer Groups
Client-Related
Network-Related
Monitoring
Messages
Agreements
CKafka Service Level Agreements
Contact Us
Glossary

VPC Network Access

PDF
フォーカスモード
フォントサイズ
最終更新日: 2026-01-05 15:16:58

Scenarios

This task uses the Python client as an example to guide you to access TDMQ for CKafka (CKafka) in the Virtual Private Cloud (VPC) network and send and receive messages.

Prerequisites

You have obtained the client connection parameters as instructed in SDK Overview.

Operation Steps

Upload pythonkafkademo from the downloaded demo to the Linux server, log in to the Linux server, and go to the pythonkafkademo directory.

Step 1: Adding Python Dependency Libraries

Run the following command to perform the installation:
pip install kafka-python
If Python 3 is used, run the following command to install python3-pip, and then install kafka-python.
yum install -y python3-pip
pip3 install kafka-python

Step 2: Producing Messages

1. Note that the configuration parameters in the message production program producer.py must be modified.
from kafka import KafkaProducer
# Create a producer.
producer = KafkaProducer(
bootstrap_servers='$domainName:$port', # Replace with your Kafka address.
api_version=(2, 8, 0), # Explicitly specify the protocol version (to be adjusted based on the cluster instance).
retries=2147483647, # Set the number of retries to the maximum value for integer data type (infinite retries).
retry_backoff_ms=1000, # Retry interval of 1 second.
acks=1 # Wait for the acknowledgment only from the leader, but not all replicas.
)

# Send messages.
for i in range(5):
msg = f"Message {i}"
future = producer.send('$topic_name', value=msg.encode('utf-8')) # $topic_name needs to be created in the console in advance, and be sure to replace it.
result = future.get(timeout=10)
print(f"Sent successfully: '{msg}' -> Partition={result.partition}, Offset={result.offset}")

producer.close()
Parameter
Description
bootstrap_servers
Access network. On the Basic Info page of the instance in the console, select the Access Mode module and copy the network information from the Network column.
topic_name
Topic name. Copy the name on the Topic List page in the console.
2. Compile and run producer.py.
3. View the running results.


4. On the Topic List page in the CKafka console, select the target topic, and choose More > Message Query to view the message just sent.

Step 3: Consuming Messages

1. Modify the configuration parameters in the consumption message program consumer.py.
from kafka import KafkaConsumer

# Create a consumer.
consumer = KafkaConsumer(
'$topic_name', # Topic name.
bootstrap_servers='$domainName:$port', # Replace with your Kafka address.
group_id='$group_id', # Specify the consumer group name.
auto_offset_reset='earliest', # Start reading from the earliest message.
api_version=(2, 8, 0), # Explicitly specify the protocol version.
enable_auto_commit=True
)

print("Start consuming messages...")

try:
for msg in consumer:
value = msg.value.decode('utf-8')
print(f"Received the message: {value}")
except KeyboardInterrupt:
print("Consumers have stopped.")
finally:
consumer.close()
Parameter
Description
bootstrap_servers
Access network. On the Basic Info page of the instance in the console, select the Access Mode module and copy the network information from the Network column.
group_id
Consumer group ID. Define the group ID according to business requirements.
topic_name
Topic name. Copy the name on the Topic List page in the console.
2. Compile and run consumer.py.
3. View the running results.

4. On the Consumer Group page in the CKafka console, select the target consumer group name, enter the topic name in the Topic Name area, and click View Details to view consumption details.



ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック