Last active
May 25, 2019 23:31
-
-
Save Jammink2/d9599f0c20586b5d0bfbb23f6bc2e622 to your computer and use it in GitHub Desktop.
iBeacon Consumer simulator for Aiven Kafka
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
# iBeacon Consumer simulator for Aiven Kafka | |
# This script receives messages from a Kafka topic | |
# usage: python ibeacon_consumer.py | |
# [email protected] | |
from kafka import KafkaConsumer | |
from time import sleep | |
# method that receives the message | |
# be sure to copy your ca.pem, service.cert and service.key to local directory from your Aiven Kafka instance. | |
consumer = KafkaConsumer( | |
"demo-topic", | |
bootstrap_servers="<URI_to_Aiven_Kafka>.aivencloud.com:27974", | |
client_id="demo-client-1", | |
group_id="demo-group", | |
security_protocol="SSL", | |
ssl_cafile="ca.pem", | |
ssl_certfile="service.cert", | |
ssl_keyfile="service.key", | |
) | |
while True: | |
raw_msgs = consumer.poll(timeout_ms=100000) | |
for tp, msgs in raw_msgs.items(): | |
for msg in msgs: | |
print("Received: {}".format(msg.value)) | |
# sleep added to show messages coming in as they are consumed | |
sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment