Kafka produce to send image

前端 未结 2 413
野的像风
野的像风 2020-12-11 11:13

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

相关标签:
2条回答
  • 2020-12-11 11:50

    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");
    
    0 讨论(0)
  • 2020-12-11 11:52

    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.

    0 讨论(0)
提交回复
热议问题