Skip to content

Instantly share code, notes, and snippets.

@Jammink2
Last active May 25, 2019 23:31
Show Gist options
  • Select an option

  • Save Jammink2/d9599f0c20586b5d0bfbb23f6bc2e622 to your computer and use it in GitHub Desktop.

Select an option

Save Jammink2/d9599f0c20586b5d0bfbb23f6bc2e622 to your computer and use it in GitHub Desktop.

Revisions

  1. Jammink2 revised this gist May 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ibeacon_consumer.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    # be sure to copy your ca.pem, service.cert and service.key to local directory from your Aiven Kafka instance.

    consumer = KafkaConsumer(
    "sample-topic",
    "demo-topic",
    bootstrap_servers="<URI_to_Aiven_Kafka>.aivencloud.com:27974",
    client_id="demo-client-1",
    group_id="demo-group",
  2. Jammink2 created this gist May 3, 2019.
    28 changes: 28 additions & 0 deletions ibeacon_consumer.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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(
    "sample-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)