Upload CSV to Event Hub ¿is it posible?

Jona 355 Reputation points
2024-04-04T04:54:02.97+00:00

Hi every one

I've been making some test and realized that a given CSV payload is around a 35% size of the equivalent JSON payload. I want to propose my boss to send to Event Hub CSV and not JSON, and here are my questions:

  • ¿is it posible?
  • The Data Generator feature of Event Hub on the Azure Portal only supports JSON
  • I've reading that by serializing any content can be pushed to Event Hub

In this SO, they state that to send CSV files to Event Hub, I have to provide the header line for every single line, so I would end up with a payload similar to JSON.

Regards

Jona

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
559 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde 28,706 Reputation points MVP
    2024-04-04T06:02:52.7766667+00:00

    Hello @Jona,

    welcome to this moderated Azure community forum.

    As you can see in this code example, the body of an Event Hub message is just a byte array, so you can send everything you want as long as you convert it to a byte array.

    You could send either each line separately (eg. as JSON) or you could send the complete file at once (if it fits).

    What is needed to send a file?

    You need to read the whole file and put it into the message body as a byte array.

    The filename could then be added in the application properties.

    This means the receiver of the message must know how to construct the file back from the message (turn the byte array into a string, construct a file out of it and give it the proper name).

    The maximum message size of an Event Hub message is 1 Mb.

    This could be a compressed message (eg. GZIP of Deflate) so the original file could be much larger at first. As you can see, you can test for the size using the batching method.

    If this size is not enough, you could store the file in a blob storage first and only forward de location and name. Then the file size is not a limitation anymore.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


  2. PRADEEPCHEEKATLA-MSFT 77,676 Reputation points Microsoft Employee
    2024-04-04T06:22:37.98+00:00

    @Jona - Thanks for the question and using MS Q&A platform.

    Yes, it is possible to send CSV files to Event Hub. However, you need to provide the header line for every single line, so you would end up with a payload similar to JSON. This means that the size reduction you are expecting may not be achieved.

    The Data Generator feature of Event Hub on the Azure Portal only only supports sending data in JSON, XML, Text, and Binary formats. CSV is not supported by the Data Generator.

    However, you can use any programming language to serialize your CSV data and send it to Event Hub. You can use the Azure Event Hubs client library for .NET, Java, Python, or JavaScript to send data to Event Hub.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments