This topic describes how to use the SDK for Python to connect to the default endpoint of a Message Queue for Apache Kafka instance and send and consume messages in a virtual private cloud (VPC).
Prerequisites
- Python is installed. For more information, see Download Python.
Note Python 2.7, 3.4, 3.5, 3.6, and 3.7 are supported.
- pip is installed. For more information, see Installation.
Install the Python library
Run the following command to install the Python library:
pip install kafka-python
Preparations
Create a Message Queue for Apache Kafka configuration file named setting.py.
kafka_setting = {
'bootstrap_servers': ["XXX", "XXX", "XXX"],
'topic_name': 'XXX',
'consumer_id': 'XXX'
}
Parameter | Description |
---|---|
bootstrap_servers | The default endpoint of the Message Queue for Apache Kafka instance. You can obtain the default endpoint in the Endpoint Information section of the Instance Details page in the Message Queue for Apache Kafka console. |
topic_name | The name of the topic. You can obtain the name of the topic on the Topics page in the Message Queue for Apache Kafka console. |
consumer_id | The name of the consumer group. Group You can obtain the name of the consumer group on the Groups page in the Message Queue for Apache Kafka console. |