from confluent_kafka import Consumerfrom unusualwhales.schema_pb2 import TickerShares# The record key selects the message type.BY_KEY = { b"ticker": TickerShares,}# CONFIG comes from the Connecting section of the Kafka overview.consumer = Consumer(CONFIG | {"group.id": "my-shares-consumer"})consumer.subscribe(["shares"])while True: msg = consumer.poll(1.0) if msg is None or msg.error(): continue message_type = BY_KEY.get(msg.key()) if message_type is None: continue event = message_type() event.ParseFromString(msg.value()) print(event)
Last modified on September 23, 2026
Was this page helpful?
Assistant
Responses are generated using AI and may contain mistakes.