Browse Source

优化调整 - hbase 动作描述

jkzlzhoujie 6 years ago
parent
commit
ec0f395614
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/main/java/com/yihu/ehr/listener/HbaseLogListener.java

+ 14 - 0
src/main/java/com/yihu/ehr/listener/HbaseLogListener.java

@ -19,6 +19,9 @@ import java.util.Map;
 */
public class HbaseLogListener implements EventListener {
    Logger log = LoggerFactory.getLogger(HbaseLogListener.class);
    private static String action_put = "Put";//添加和修改单个字段值
    private static String action_del = "DeleteColumn";//删除单个字段值
    private static String action_delAll = "DeleteFamily";//删除整行
    @Override
@ -35,12 +38,23 @@ public class HbaseLogListener implements EventListener {
            for (Cell cell : sepEvent.getKeyValues()) {
                String cloumn = Bytes.toString(CellUtil.cloneQualifier(cell));
                String value = Bytes.toString(CellUtil.cloneValue(cell));
                String action = "";
                if(cell.toString().contains(action_put)){
                    action = action_put;
                }else if(cell.toString().contains(action_del)){
                    action = action_del;
                }else if(cell.toString().contains(action_delAll)){
                    action = action_delAll;
                }
                dataMap.put("action", action);
                dataMap.put(cloumn, value);
            }
            log.debug("message: " + dataMap.toString());
            Gson gson = new Gson();
            String jsonData = gson.toJson(dataMap);
            producer.sendMessage(jsonData);
            //测试 删除格式 字段为空 的数据
        }
        log.info("sep Events end");
    }