Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iBeacon Consumer simulator for Aiven Kafka
# iBeacon Consumer simulator for Aiven Kafka
# This script receives messages from a Kafka topic
# usage: python ibeacon_consumer.py
# jammink@aiven.io
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