I managed to integrate Hbase
into a Spring
app using HbaseTemplate
:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class ItemRepositoryImpl implements ItemRepository {
@Autowired
private HbaseTemplate hbaseTemplate;
@Override
public List<Item> findAll() {
Scan scan = new Scan();
scan.addColumn(CF, CQ);
hbaseTemplate.find("TABLE_NAME", scan, (result, rowNum) -> {
return new Item(...)
});
}
}
However, the connection to Hbase is opened every time I run findAll()
(and closed just after). I read somewhere that the way to keep the connection alive is to use Connection
and Table
for calls to Hbase. The problem is that HbaseTemplate
uses HConnection
and HTableInterface
.
How can I keep my connection alive using HbaseTemplate
? Initiating a new connection is very time-consuming and I'd like to do it only once. Alternatively is there any other way to connect to Hbase from a Spring
app?
I'm using:
org.springframework.data:spring-data-hadoop:2.5.0.RELEASE
org.apache.hbase:hbase-client:1.1.2