Browse Source

数据转换成json

jkzlzhoujie 6 years ago
parent
commit
60683c9eb9
1 changed files with 9 additions and 6 deletions
  1. 9 6
      src/main/java/com/yihu/ehr/listener/HbaseLogListener.java

+ 9 - 6
src/main/java/com/yihu/ehr/listener/HbaseLogListener.java

@ -1,5 +1,6 @@
package com.yihu.ehr.listener;
import com.google.gson.Gson;
import com.ngdata.sep.EventListener;
import com.ngdata.sep.SepEvent;
import com.yihu.ehr.kafka.Producer;
@ -28,16 +29,18 @@ public class HbaseLogListener implements EventListener {
            System.out.println("  row = " + Bytes.toString(sepEvent.getRow()));
            log.debug("  table = " + Bytes.toString(sepEvent.getTable()));
            log.debug("  row = " + Bytes.toString(sepEvent.getRow()));
            Map<String, Object> json = new HashMap<String, Object>();
            json.put("table",Bytes.toString(sepEvent.getTable()));
            json.put("rowKey",Bytes.toString(sepEvent.getRow()));
            Map<String, Object> dataMap = new HashMap<String, Object>();
            dataMap.put("table",Bytes.toString(sepEvent.getTable()));
            dataMap.put("rowKey",Bytes.toString(sepEvent.getRow()));
            for (Cell cell : sepEvent.getKeyValues()) {
                String cloumn = Bytes.toString(CellUtil.cloneQualifier(cell));
                String value = Bytes.toString(CellUtil.cloneValue(cell));
                json.put(cloumn, value);
                dataMap.put(cloumn, value);
            }
            log.debug("message: " + json.toString());
            producer.sendMessage(json.toString());
            log.debug("message: " + dataMap.toString());
            Gson gson = new Gson();
            String jsonData = gson.toJson(dataMap);
            producer.sendMessage(jsonData);
        }
        log.info("sep Events end");
    }