cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Can I connect to Eventhub using Kafka API? Which is the preferred way?

User16869510359
Esteemed Contributor
 
1 ACCEPTED SOLUTION

Accepted Solutions

User16869510359
Esteemed Contributor

Yes, it's possible to use Kafka API to connect to the eventhub. Eventhub supports the usage of Kafka API to stream the data from the Eventhub

Reference:

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-for-kafka-ecosystem-overview

Sample program:

%python
 
eh_sasl = 'kafkashaded.org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://myazure-train-eventhub.us.servicebus.windows.net/;SharedAccessKeyName=manage-policy;SharedAccessKey=xxxxxXXXXXXXXX/xxxxxxx;';
 
inputStream = spark.readStream \
.format("kafka") \
.option("subscribe", "dataabricks-stream-event") \
.option("kafka.bootstrap.servers", "azure-training-us.servicebus.windows.net:9093") \
.option("kafka.sasl.mechanism", "PLAIN") \
.option("startingOffsets","earliest") \
.option("kafka.security.protocol", "SASL_SSL") \
.option("kafka.sasl.jaas.config", eh_sasl) \
.option("kafka.request.timeout.ms", "60000") \
.option("kafka.session.timeout.ms", "30000") \
.option("failOnDataLoss", "false") \
.load()

View solution in original post

1 REPLY 1

User16869510359
Esteemed Contributor

Yes, it's possible to use Kafka API to connect to the eventhub. Eventhub supports the usage of Kafka API to stream the data from the Eventhub

Reference:

https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-for-kafka-ecosystem-overview

Sample program:

%python
 
eh_sasl = 'kafkashaded.org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://myazure-train-eventhub.us.servicebus.windows.net/;SharedAccessKeyName=manage-policy;SharedAccessKey=xxxxxXXXXXXXXX/xxxxxxx;';
 
inputStream = spark.readStream \
.format("kafka") \
.option("subscribe", "dataabricks-stream-event") \
.option("kafka.bootstrap.servers", "azure-training-us.servicebus.windows.net:9093") \
.option("kafka.sasl.mechanism", "PLAIN") \
.option("startingOffsets","earliest") \
.option("kafka.security.protocol", "SASL_SSL") \
.option("kafka.sasl.jaas.config", eh_sasl) \
.option("kafka.request.timeout.ms", "60000") \
.option("kafka.session.timeout.ms", "30000") \
.option("failOnDataLoss", "false") \
.load()

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.