druid
druid copied to clipboard
How to send customize type byTranquilizer to druid ?
Hi
I want to send customize type to druid.
`
DataSourceConfig
public class BaseTimestamper implements Timestamper
@Override
public DateTime timestamp(Object arg0) {
DateTime dateTime = new DateTime(DateTimeZone.forID("Asia/Shanghai"));
return dateTime;
}
}
public class BaseJavaObjectWriter
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<T> 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.