I have the following Kafka producer code. I want to know if I can send image file instead of JSON file? Is there any code reference sending an image file through Kafka produ
Image can be sent as byte array in message value. so your code will be changed as given.
props.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
You can send an image by following these simple steps:
1) convert your image into bytes array ( by search for "how to get bytes of an image file )
2) change this line from :-
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
to:-
props.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
3) give your bytesarray of your image file
and, you are good to go.