Springboot整合lotdb ,詳細原始碼
阿新 • • 發佈:2021-02-06
技術標籤:大資料
最近接到一個專案,是要使用springboot 整合lotdb 來處理大量的資料
相關使用記錄:
這裡使用了lotdb 資料庫中的session ,具體jdbc 可以參照lotdb 的開發文件。
在使用之前要啟動lotdb 服務
相關操作如下:
- 進入解壓檔案的sbin 目錄
- 進入shell 操作
- 找到自己的對應的指令
3.1 在window 系統下cmd 進入,並輸入
./start-server.bat
3.2在linux 系統進入終端,輸入
./start-server.sh
新建Springboot 專案
在pom 中加入
這裡的版本資訊要對應自己的安裝資訊
< dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<version>0.11.2</version>
</dependency>
檢視自己的安裝的版本資訊操作:進入lotdb 的cli 操作介面輸入:
show version
- 新建配置類
在application.properties 檔案中追加
# 設定埠號
server.port=8089
# 設定lotdb 的相關資訊
spring.lotdb.hort=127.0.0.1
spring.lotdb.port=6667
spring.lotdb.username=root
spring.lotdb.password=root
新建一個class:LOTDBConfig.class
package com.hadwinling.lotdb.config;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.session.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @description:
* @author: hadwinling
* @time: 2021/2/5 下午9:18
*/
@Configuration
public class LOTDBConfig {
@Value("${spring.lotdb.hort}")
private String hort;
@Value("${spring.lotdb.port}")
private int port;
@Value("${spring.lotdb.username}")
private String username;
@Value("${spring.lotdb.password}")
private String password;
@Bean
public Session lotdbSession() {
Session session = new Session(hort, port, username, password);
try {
session.open(false);
} catch (IoTDBConnectionException e) {
e.printStackTrace();
}
return session;
}
}
- 手寫相關服務
以設定儲存組為例:
package com.hadwinling.lotdb.service;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @description:
* @author: hadwinling
* @time: 2021/2/5 下午9:24
*/
@Service
public class LotdbService {
@Autowired
private Session lotdbSession;
/**
* 根據storageGroupId 設定儲存組
* @param storageGroupId
*/
public void setStorageGroup(String storageGroupId) {
try {
lotdbSession.setStorageGroup(storageGroupId);
} catch (IoTDBConnectionException e) {
e.printStackTrace();
} catch (StatementExecutionException e) {
e.printStackTrace();
}
}
}
- 寫控制器
package com.hadwinling.lotdb.controller;
import com.hadwinling.lotdb.service.LotdbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @description:
* @author: hadwinling
* @time: 2021/2/5 下午9:35
*/
@Controller
public class LotdbController {
@Autowired
private LotdbService lotdbService;
@GetMapping("/")
@ResponseBody
public String setStorageGroup(){
lotdbService.setStorageGroup("root.ling");
return "over";
}
}
- 結果
- 原始碼,歡迎star