Springboot整合IoTB的實(shí)現(xiàn)示例
一、引入依賴
<!--引入iotdb session依賴--> <dependency> <groupId>org.apache.iotdb</groupId> <artifactId>iotdb-session</artifactId> <version>1.3.2</version> </dependency>
二、配置IotDB連接
iotdb: username: root password: root ip: 192.168.56.10 port: 6667 #批量操作數(shù)量 maxSize: 200
三、創(chuàng)建配置類
import lombok.extern.slf4j.Slf4j;
import org.apache.iotdb.session.pool.SessionPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@Slf4j
public class IotDBSessionConf {
@Value("${iotdb.username}")
private String username;
@Value("${iotdb.password}")
private String password;
@Value("${iotdb.ip}")
private String ip;
@Value("${iotdb.port}")
private int port;
@Value("${iotdb.maxSize}")
private int maxSize;
//Session線程池
private static SessionPool pool;
@Bean
public SessionPool initSessionPool() {
if(pool==null) {
log.info(">>>>>SessionPool初始化....");
pool =
new SessionPool.Builder()
.user(username)
.password(password)
.host(ip)
.port(port)
.maxSize(maxSize)
.build();
}
return pool;
}
}
四、創(chuàng)建service和實(shí)現(xiàn)類
@Service
@RequiredArgsConstructor
public class IoTDBServiceImpl implements IoTDBService {
private final IotDBSessionConf conf;
@Override
public SessionDataSetWrapper executeQueryStatement(String sql) {
SessionPool sessionPool = conf.initSessionPool();
SessionDataSetWrapper wrapper = null;
try {
wrapper = sessionPool.executeQueryStatement(sql);
} catch (IoTDBConnectionException e) {
throw new RuntimeException(e);
} catch (StatementExecutionException e) {
throw new RuntimeException(e);
}
return wrapper;
}
@Override
public SessionDataSetWrapper executeRawDataQuery(List<String> path, long startTime, long endTime, long timeOut) {
SessionPool sessionPool = conf.initSessionPool();
SessionDataSetWrapper wrapper = null;
try {
wrapper = sessionPool.executeRawDataQuery(path, startTime, endTime, timeOut);
} catch (IoTDBConnectionException e) {
throw new RuntimeException(e);
} catch (StatementExecutionException e) {
throw new RuntimeException(e);
}
return wrapper;
}
}五、創(chuàng)建工具類
@RequiredArgsConstructor
public class IoTDBUtils {
private final IoTDBService iotDBService;
/**
* 根據(jù)自定義SQL語句執(zhí)行查詢
* @param sql
* @return
*/
SessionDataSetWrapper executeQueryStatement(String sql) {
return iotDBService.executeQueryStatement(sql);
}
/**
* 根據(jù)時(shí)間區(qū)間執(zhí)行查詢數(shù)據(jù)
* @param paths 時(shí)間序列
* @param startTime 開始時(shí)間戳(包含)
* @param endTime 結(jié)束時(shí)間戳(不包含)
* @param timeOut 超時(shí)時(shí)間
* @return
*/
SessionDataSetWrapper executeRawDataQuery(List<String> paths, long startTime, long endTime, long timeOut){
return iotDBService.executeRawDataQuery(paths, startTime, endTime, timeOut);
}
}
單元測試
@SpringBootTest(classes = IotDBSessionConfTest.class)
public class IotDBSessionConfTest {
// 測試連接
@Test
public void testInitSessionPool() {
IotDBSessionConf conf = new IotDBSessionConf();
SessionPool sessionPool = conf.initSessionPool();
System.out.println(sessionPool.getVersion());
}
}到此這篇關(guān)于Springboot整合IoTB的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Springboot整合IoTB內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
springMvc請(qǐng)求的跳轉(zhuǎn)和傳值的方法
本篇文章主要介紹了springMvc請(qǐng)求的跳轉(zhuǎn)和傳值的方法,這里整理了幾種跳轉(zhuǎn)方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-02-02
Java實(shí)現(xiàn)獲取圖片和視頻文件的Exif信息
這篇文章將重點(diǎn)為大家介紹一下如何使用Java編程語言結(jié)合metadata-extractor去自動(dòng)獲取全景圖片的Exif信息,獲取照片的拍攝坐標(biāo)信息,感興趣的可以了解一下2022-11-11
詳解Mybatis中javaType和ofType的區(qū)別
本文主要介紹了詳解Mybatis中javaType和ofType的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05
SpringBoot3.X 整合 MinIO 存儲(chǔ)原生方案
本文詳細(xì)介紹了SpringBoot3.X整合MinIO的原生方案,從環(huán)境搭建到核心功能實(shí)現(xiàn),涵蓋了文件上傳、下載、刪除等常用操作,并補(bǔ)充了異常處理、參數(shù)校驗(yàn)、安全實(shí)踐等內(nèi)容,感興趣的朋友一起看看吧2025-07-07
深入解析Java的Spring框架中的混合事務(wù)與bean的區(qū)分
這篇文章主要介紹了Java的Spring框架中的混合事務(wù)與bean的區(qū)分,Spring是Java的SSH三大web開發(fā)框架之一,需要的朋友可以參考下2016-01-01
Java Apache POI實(shí)現(xiàn)導(dǎo)出Excel的實(shí)戰(zhàn)指南
在企業(yè)級(jí)開發(fā)中,Excel 數(shù)據(jù)導(dǎo)出是高頻需求,本文基于 Apache POI 實(shí)現(xiàn)災(zāi)情速報(bào)員數(shù)據(jù) Excel 導(dǎo)出功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2026-04-04
在SpringBoot中通過jasypt進(jìn)行加密解密的方法
今天小編就為大家分享一篇關(guān)于在SpringBoot中通過jasypt進(jìn)行加密解密的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-01-01
Spring?Boot最經(jīng)典的20道面試題你都會(huì)了嗎
Spring Boot是現(xiàn)代化的Java應(yīng)用程序開發(fā)框架,具有高度的靈活性和可擴(kuò)展性,下面這篇文章主要給大家介紹了關(guān)于Spring?Boot最經(jīng)典的20道面試題,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-06-06

