How to send customize type byTranquilizer to druid?

Hi

I want to send customize type to druid.

DataSourceConfig customerConfig = druidConfig.getDataSource(name);

DruidBeams.Builder<?,?> beamBuilder = DruidBeams.fromConfig(customerConfig,new BaseTimestamper(), new BaseJavaObjectWriter());

sender = beamBuilder.buildTranquilizer(customerConfig.tranquilizerBuilder());

sender.start();

public class BaseTimestamper implements Timestamper {

@Override

public DateTime timestamp(Object arg0) {

DateTime dateTime = new DateTime(DateTimeZone.forID(“Asia/Shanghai”));

return dateTime;

}

}

public class BaseJavaObjectWriter implements JavaObjectWriter {

private static Logger log = Logger.getLogger(BaseJavaObjectWriter.class);

@Override

public byte asBytes(T t) {

byte buff = null;

try {

buff = JSON.toJSONString(t).getBytes(“UTF-8”);

} catch (Exception e) {

log.error(“to byte error”, e);

}

return buff;

}

@Override

public byte batchAsBytes(Iterator iterator) {

byte data = null;

ByteArrayOutputStream bos = new ByteArrayOutputStream();

try {

while(iterator.hasNext()){

T t = iterator.next();

try {

bos.write(asBytes(t));

} catch (IOException e) {

log.error(“batch to byte error”, e);

}

}

bos.flush();

data = bos.toByteArray();

}catch (Exception e) {

log.error(“batch to byte error”, e);

}finally {

try {

bos.close();

} catch (IOException e) {

}

}

return data;

}

@Override

public String contentType() {

return “application/json”;

}

}

``

but i encountered some problems:

2017-07-05 17:20:02 ERROR DruidUtil:164 - com.metamx.tranquility.tranquilizer.MessageDroppedException: Message dropped

if i use the default type (https://github.com/druid-io/tranquility/blob/master/core/src/test/java/com/metamx/tranquility/example/JavaExample.java), it is success.

batchAsBytes should write a JSON array, but your implementation is just writing the JSON objects side by side. Try adding some brackets and commas to make a real array out of it.