This topic describes how a Python client uses SDK for Python to connect to the default endpoint of Message Queue for Apache Kafka in a virtual private cloud (VPC) and send and subscribe to messages.
Prerequisites
- Install PythonNote Python 2.7, 3.4, 3.5, 3.6, and 3.7 are supported.
- Install pip
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. You can obtain the default endpoint in the Basic 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. You can obtain the name of the consumer group on the Consumer Groups page in the Message Queue for Apache Kafka console. |