# hbase-spring-boot-starter **Repository Path**: spring208/hbase-spring-boot-starter ## Basic Information - **Project Name**: hbase-spring-boot-starter - **Description**: hbase-spring-boot-starter 是基于asynchbase的client封装的hbase orm 保持asynchbase异步特性的同时避免了原生客户端的复杂依赖冲突问题 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2020-07-15 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 项目介绍 # hbase-spring-boot-starter 是基于asynchbase的client封装的hbase orm 保持asynchbase异步特性的同时避免了原生客户端的复杂依赖冲突问题 # 编译打包 # mvn clean install -DskipTests # API使用 # > 添加配置 `` hbase.client.retries.number=2 hbase.increments.buffer_size=3 hbase.zookeeper.quorum = 127.0.0.1,127.0.0.2,127.0.0.3 //zk地址 hbase.host = hbase1.example.com:10.9.35.28;hbase2.example.com:10.9.35.29;hbase3.example.com:10.9.35.30 //hbase主机名无法访问可映射静态IP `` > `` private static final String TABLE_NAME = "SEA_TEST"; private static final String FAMILY = "info"; @Autowired private HBaseTemplate hBaseTemplate; @Test public void testDelete() throws InterruptedException { List list = new ArrayList(); hBaseTemplate.delete( Student.class, (o,e) -> { if (o != null) { System.out.println("==== o ======"+o); list.add(o); return o; } if (e != null) { System.out.println("================================="); System.out.println(e.getClass()); System.out.println("================================="); e.printStackTrace(); list.add(e); } return null; }, "李3","李4"); while (list.size()<=0){ Thread.sleep(1000L); } Object o = list.get(0); if(o instanceof Exception){ Assert.assertTrue(false); }else{ Assert.assertTrue(true); } } @Test public void testGet() throws InterruptedException { String prefix = "李"; for (int i = 5; i <= 8; i++) { String rowKey = prefix + i; System.out.println(rowKey); System.out.println(hBaseTemplate.get(Student.class, rowKey, (student1, e) -> { if (student1 != null) { System.out.println("============================="); System.out.println(JSON.toJSONString(student1)); System.out.println("============================="); return student1; } if (e!=null) { e.printStackTrace(); } return null; })); } Thread.sleep(1000000L); } @Test public void testBatchPut() throws Exception { Student stu1 = new Student(); stu1.setName("王5"); stu1.setAge("30"); stu1.setSex("男"); stu1.setAddress("李5家的地址"); Student stu2 = new Student(); stu2.setName("王6"); stu2.setAge("30"); stu2.setSex("男"); stu2.setAddress("李6家的地址"); Student stu3 = new Student(); stu3.setName("王7"); stu3.setAge("30"); stu3.setSex("男"); stu3.setAddress("李7家的地址"); Student stu4 = new Student(); stu4.setName("8"); stu4.setAge("30"); stu4.setSex("男"); stu4.setAddress("李8家的地址"); List list = Arrays.asList(stu1, stu2, stu3, stu4); hBaseTemplate.put(list, (o, e) -> { if (o != null) { System.out.println("==== o ======"+o); return false; } if (e != null) { System.out.println("============================="); System.out.println(e.getClass()); System.out.println("============================="); e.printStackTrace(); } return null; }); Thread.sleep(1000000); } @Test public void testPut() throws Exception { Student stu = new Student(); stu.setName("李四22222"); stu.setAge("30"); stu.setSex("男"); stu.setAddress("李四家的地址"); // Student zhangsang = template.get(Student.class, "zhangsang", ); hBaseTemplate.put(stu, (o, e) -> { if (o != null) { System.out.println("==== o ======"+o); return o; } if (e != null) { System.out.println("=============================="); System.out.println(e.getClass()); System.out.println("=============================="); e.printStackTrace(); } return null; }); Student student = hBaseTemplate.get(Student.class, stu.getName(), (student1, e) -> { if (student1 != null) { System.out.println("|||||||||||||||"+JSON.toJSONString(student1)); } if (e!=null) { e.printStackTrace(); } return null; }); System.out.println("========="+JSON.toJSONString(student)); } @Test public void extend() { HBaseTemplate.CallBack> scanCB = new HBaseTemplate.CallBack() { @Override public List doInTable(HBaseClient client) { Scanner scanner = client.newScanner("SEA_TEST"); scanner.setStartKey("0"); ArrayList> rows; List stus = new ArrayList<>(); try { while ((rows = scanner.nextRows().joinUninterruptibly()) != null) { for (ArrayList row : rows) { stus.add(AnnotationParser.parseGetResponse(Student.class, row)); } } } catch (Exception e) { e.printStackTrace(); } return stus; } }; List students = scanCB.doInTable(hBaseTemplate.getClient()); System.out.println(JSON.toJSONString(students)); } ``