I am sending a json object(in python) to Azure Event Hub which is routed to Blob Storage via Event Capture feature of Event Hub. This file gets stored in Apache AVRO. When I upload the file on online AVRO reader I see something like this ..AVRO Reader Snip
The actual data is in body of the image. I don't want Azure Event Hub to encode my data to base64. What changes should I make to my below code.
producer = EventHubProducerClient.from_connection_string(conn_str=EVENTHUB_CONNECTION_STR, eventhub_name=eventhub)
async with producer:
dictionary_obj = {}
dictionary_obj['id'] = 1
dictionary_obj['Name'] = 'Alex'
dictionary_obj['Attr1'] = 1
MESSAGE = json.dumps(dictionary_obj)
event_data_batch = await producer.create_batch()
event_data_batch.add(EventData(MESSAGE))
await producer.send_batch(event_data_batch)
await producer.close()
CodePudding user response:
Azure Event Hubs handles the data in the message body as an opaque byte array. It never encodes it prior to avro write.
CodePudding user response:
We can use a python script to decode the content. Below is the sample python script.
import base64
image = open('deer.gif', 'rb')
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
image_64_decode = base64.decodestring(image_64_encode)
image_result = open('deer_decode.gif', 'wb') # create a writable image and write the decoding result
image_result.write(image_64_decode)
Refer to this blog to understand more about this.
