Send Custom json to Event Hub from Synapses Notebook

Admin (KK) 136 Reputation points
2023-06-11T10:49:50.5266667+00:00

Hello,

I have an compressed json which i want to send to eventhub using pyspark notebook. I installed azure-eventhub library on the pyspark pool. I am using the following code.

from azure.eventhub.aio import EventHubProducerClient
from azure.eventhub import EventData

eventHubConnectionString = <<connectionstring>>

async def sendToEventHub(jsonString):
    compressedData = gzip.compress(jsonString.encode('utf-8'))
    encodedData = b64encode(compressedData)
    producer = EventHubProducerClient.from_connection_string(eventHubConnectionString)
    async with producer:
        eventDataBatch = await producer.create_batch()
        eventDataBatch.add(EventData(encodedData))
        #eventDataBatch.add(EventData(jsonString))

However it fails with this error message

ModuleNotFoundError: No module named 'EventHubProducerClient'

PS - This code works in azure functions.

Do i need to use a different library or anything else to fix this.

Thanks in advance.

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
716 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,357 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HimanshuSinha-msft 19,486 Reputation points Microsoft Employee Moderator
    2023-06-12T19:12:16.5533333+00:00

    Hello @Admin (KK) ,

    Thanks for using Microsoft Q&A .

    I think you will have to install the package which you are using "azure.eventhub" . I did tried to the code without the install I also got the same error . Please follow the steps provided here and you should be good .

    Thanks
    Himanshu


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.