import uuidfrom kafka import KafkaConsumer,TopicPartition,OffsetAndMetadataconsumer = KafkaConsumer(// Your topic name. Enter the topic name in the above figure here.'in-633a268c-XXXX-4a4c-XXXX-7a9a1a7baXXXX',group_id = uuid.uuid4().hex,auto_offset_reset='earliest',// Kafka service address. Enter the access point information in the above figure here.bootstrap_servers = ['ckafka-lweXXXXk.ap-guangzhou.ckafka.tencentcloudmq.com:6012'],security_protocol = "SASL_PLAINTEXT",sasl_mechanism = 'PLAIN',// SASL information. Concatenate the Kafka instance information and username with # and enter it here. The instance information is in the access point information.sasl_plain_username = "ckafka-lweXXXXk#cls-2pGgXXX",// SASL information. Enter the password in the above figure here.sasl_plain_password = "8uleOOPXXX",api_version = (0,10,0))print('begin')for message in consumer:print('begins')print ("Topic:[%s] Partition:[%d] Offset:[%d] Value:[%s]" % (message.topic, message.partition, message.offset, message.value))print('end')
Feedback