rpc - send compressed message using avro -
i have pojo in need send end-poind (some server). have decided using avro.
so far have created avro schema , generated datafilewriter:
genericrecord user1 = new genericdata.record(schema); user1.put("name", "jenny"); user1.put("favorite_color", "green"); genericrecord user2 = new genericdata.record(schema); user2.put("name", "kevin"); user2.put("favorite_color", "red"); datumwriter<genericrecord> datumwriter = new genericdatumwriter<genericrecord>(schema); datafilewriter<genericrecord> datafilewriter = new datafilewriter<genericrecord>(datumwriter); datafilewriter.create(schema, schemafile); datafilewriter.append(user1); datafilewriter.append(user2);
this have far , i'm missing following:
i compress data before sending it, rather doing using snappy, how should combine code?
update: added these lines:
// use snappy compression codecfactory codecfactory = codecfactory.snappycodec(); datafilewriter.setcodec(codecfactory);
but i'm not sure yet if job.
using this:
public byte[] serialize(t objecttoserialize) { bytearrayoutputstream out = new bytearrayoutputstream(); datumwriter<t> reflectdatumwriter = new reflectdatumwriter<t>(avroschema); datafilewriter<t> filewriter = null; try { filewriter = new datafilewriter<t>(reflectdatumwriter); filewriter.setcodec(codecfactory.snappycodec()); filewriter.create(avroschema, out); filewriter.append(objecttoserialize); filewriter.close(); } catch (exception e) { log.error(e); return null; } return out.tobytearray(); }
Comments
Post a Comment