You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Per Steffensen <pe...@gmail.com> on 2017/02/13 16:29:29 UTC

Producer accept InputStream or ByteBuffer

Hi

Sorry if this has been asked before. I have not been able to find it.

It seems to me that Kafka serializer has to provide a byte-array for 
Kafka. So if you want to send something to Kafka you have to make it 
into byte-array form. That may not be very efficient in case the data 
you want to send is not already isolated in dedicated byte-array. E.g
1) If you have a byte-array where you want to send everything except for 
the first 10 bytes. You would need to copy the entire byte-array (except 
for the first 10 bytes) into a new byte-array (10 bytes shorter than the 
original one)
2) If you have InputStream (that is not byte-array based)

Is there some way to hand over data to Kafka in another way than using a 
byte-array. E.g. hand it a InputStream, a ByteBuffer or whatever. My 
concrete case is that I have lots and lots of fairly small messages I 
want to send to Kafka. For each message I already have the data in a 
byte-array, but the first 10 bytes of that byte-array should not be sent 
in the Kafka message.

Regards, Per Steffensen