Skip to content

Instantly share code, notes, and snippets.

@Roymprog
Roymprog / read_events.py
Created September 18, 2025 07:47
Spark structured streaming read events from Azure Eventhubs
def read_events():
TOPIC = "topic"
BOOTSTRAP_SERVERS = "server.servicebus.windows.net:9093"
EH_SASL = """kafkashaded.org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://..."""
return (spark.readStream
.format("kafka")
.option("subscribe", TOPIC)
.option("kafka.bootstrap.servers", BOOTSTRAP_SERVERS)
.option("kafka.sasl.mechanism", "PLAIN")