2017-11-13 5 views
0

간단한 RESTFull API을 작성하여 HBase에 액세스 할 계획입니다. 내가 보았습니다 파이썬 해피베이스,하지만 내 클러스터 kerberised입니다. 이제 나는 입니다.Hadoop HBASE가있는 스프링 부트 REST

간단한 API REST를 사용하여 Solr Cloud스프링 부트.

Hbase에서도 동일한 작업을 수행 할 수 있습니까? 내가 봄 부팅 '원사 앱' =>https://spring.io/guides/gs/yarn-basic/

또는 봄 하둡를 사용하는 경우
나는 아무 생각이 없습니다. =>https://projects.spring.io/spring-hadoop/

정말로 간단한 API가 필요합니다.

도움 주셔서 감사합니다.

답변

0

xml없이 spring boot restful 응용 프로그램에서 hbase를 사용하기위한 간단한 데모 프로젝트를 작성했습니다.

이 데모는 주로 spring-data-hadoop 및 hbase-client에 따라 다릅니다.

Gradle을 종속 :

compile('org.springframework.boot:spring-boot-starter-data-rest') 
compile('org.springframework.boot:spring-boot-starter-web') 
compile 'org.springframework.data:spring-data-hadoop:2.5.0.RELEASE' 
compile('org.apache.hbase:hbase-client:1.3.1'){ 
    exclude group :'log4j',module:'log4j' 
    exclude group :'org.slf4j',module:'slf4j-log4j12' 
    exclude group: 'javax.servlet', module: 'servlet-api' 
} 
compile('org.springframework.boot:spring-boot-configuration-processor') 
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 

구성 봄 부팅의 application.properties에서 HBase를 연결 매개 변수 (없음 XML!) :

spring.data.hbase.zkQuorum=192.168.0.109:2181 
spring.data.hbase.zkBasePath=/hbase 
spring.data.hbase.rootDir=file:///home/hbase-1.2.2 

클래스 HbaseProperties.java :

@ConfigurationProperties(prefix = "spring.data.hbase") 
public class HbaseProperties { 
    // Addresses of all registered ZK servers. 
    private String zkQuorum; 

    // Location of HBase home directory 
    private String rootDir; 

    // Root node of this cluster in ZK. 
    private String zkBasePath; 

    // getters and setters... 

} 

HbaseConfig.java, 구성을 HbaseTemplate에 삽입하십시오 :

import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.boot.context.properties.EnableConfigurationProperties; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.hadoop.hbase.HbaseTemplate; 

@Configuration 
@EnableConfigurationProperties(HbaseProperties.class) 
public class HbaseConfig { 

    @Autowired 
    private HbaseProperties hbaseProperties; 

    @Bean 
    public HbaseTemplate hbaseTemplate() { 
     org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create(); 
     configuration.set("hbase.zookeeper.quorum", this.hbaseProperties.getZkQuorum()); 
     configuration.set("hbase.rootdir", this.hbaseProperties.getRootDir()); 
     configuration.set("zookeeper.znode.parent", this.hbaseProperties.getZkBasePath()); 
     return new HbaseTemplate(configuration); 
    } 

} 

서비스 클래스, 우리는 지금 구성 HbaseTemplate를 사용할 수 있습니다

import javax.annotation.PostConstruct; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.data.hadoop.hbase.HbaseTemplate; 
import org.springframework.stereotype.Service; 

import com.zql.hbasedemo.vo.Quote; 

@Service 
public class FeedService { 
    @Autowired 
    private HbaseTemplate hbaseTemplate; 

    @PostConstruct 
    public void test(){ 
     Quote quote = new Quote(); 
     quote.setEventType("ft"); 
     quote.setHandicap("4"); 
     quote.setMarket("OU"); 
     quote.setMatchId("27350208"); 
     quote.setSelection("OVER"); 
     quote.setPrice("1.93"); 
     saveQuote(quote); 
    } 

    public Quote saveQuote(Quote quote) { 
     hbaseTemplate.put("quotes", quote.getMatchId(), "data", quote.getMarket() + ":" + quote.getSelection(), 
      quote.getPrice().getBytes()); 
     return quote; 
    } 
} 

나머지 컨트롤러.

@RestController 
public class FeedController { 
    @Autowired 
    private FeedService feedService; 

    @SuppressWarnings({ "unchecked", "rawtypes" }) 
    @PostMapping(value = "/feed/quote", consumes = "application/json", produces = "application/json") 
    public ResponseEntity<Quote> saveQuote(@RequestBody Quote quote) { 
     Quote result = feedService.saveQuote(quote); 
     return new ResponseEntity(result, new HttpHeaders(), HttpStatus.OK); 
    } 
} 
관련 문제