<jupyter_start><jupyter_text>🦀 Kafka Consumer - Partition 1--- Let's create a consumer<jupyter_code>from kafka import TopicPartition
from kafka import KafkaConsumer
import json

from config.kafka_config import *

group_id = "my_pizza_group"
timeout_ms=5000

topic_name_partitioned = topic_name +"_partitioned"

consumer_partition_1 = KafkaConsumer(
        group_id=group_id+"_partitioned",
        bootstrap_servers=hostname+":"+str(port),
        security_protocol="SSL",
        ssl_cafile=cert_folder+"/ca.pem",
        ssl_certfile=cert_folder+"/service.cert",
        ssl_keyfile=cert_folder+"/service.key",
        value_deserializer = lambda v: json.loads(v.decode('ascii')),
        key_deserializer = lambda v: json.loads(v.decode('ascii')),
        auto_offset_reset='earliest',
        max_poll_records = 10
    )<jupyter_output><empty_output><jupyter_text>Read from **partition 1**<jupyter_code>consumer_partition_1.assign([TopicPartition(topic_name_partitioned, 1)])
consumer_partition_1.subscription()
for message in consumer_partition_1:
    print ("p=%d o=%d value=%s" % (message.partition,
                                   message.offset,
                                   message.value))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11057304277643261, 'fraction_numerical': 0.010492332526230832, 'mean_word_length': 3.8818897637795278, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '446752', 'license': 'Apache-2.0', 'n_tokens_mistral': 412, 'n_tokens_neox': 393, 'n_words': 63, 'path': '03 - 02 - Consumer - Partition 1.ipynb', 'repo_name': 'srikanth-platformatory/python-notebooks-for-apache-kafka', 'size': '1239'}