Last active
May 8, 2022 18:53
-
-
Save Silvertongue26/54f0d60151047323b48d44398336d498 to your computer and use it in GitHub Desktop.
Part of zookeeper_kafka_pyspark_polarity-analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import libraries | |
from kafka import KafkaConsumer | |
import json | |
topic_name = 'TW_ANALYSIS' | |
# Creata Kafka consumer, same default configuration frome the producer | |
consumer = KafkaConsumer( | |
topic_name, | |
bootstrap_servers=['localhost:9092'], | |
api_version=(2, 0, 2), | |
# Deserialize the string from the producer since it comes in hex | |
value_deserializer=lambda x: json.loads(x.decode('utf-8'))) | |
# Message loader from Json | |
for message in consumer: | |
tweets = json.loads(json.dumps(message.value)) | |
print(tweets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part of zookeeper_kafka_pyspark_polarity-analysis