Springboot整合IoTB的實現(xiàn)示例
更新時間:2025年12月23日 10:40:47 作者:moxiaoran5753
本文主要介紹了Springboot整合IoTB的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
一、引入依賴
<!--引入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和實現(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ù)時間區(qū)間執(zhí)行查詢數(shù)據(jù)
* @param paths 時間序列
* @param startTime 開始時間戳(包含)
* @param endTime 結(jié)束時間戳(不包含)
* @param timeOut 超時時間
* @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的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)Springboot整合IoTB內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot與SpringMVC中參數(shù)傳遞的原理解析
這篇文章主要介紹了SpringBoot與SpringMVC中參數(shù)傳遞的原理,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-07-07
解決Spring Boot 在localhost域奇怪的404問題(Mac book pro)
這篇文章主要介紹了解決Spring Boot 在localhost域奇怪的404問題(Mac book pro),需要的朋友可以參考下2017-09-09
Springboot之idea之pom文件圖標(biāo)不對問題
這篇文章主要介紹了Springboot之idea之pom文件圖標(biāo)不對問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04
Spring在多線程下@Resource注入為null的問題
這篇文章主要介紹了Spring在多線程下@Resource注入為null的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02
Java中@SneakyThrows 注解的應(yīng)用場景
本文介紹了Lombok的@SneakyThrows注解在Java異常處理中的使用,該注解允許開發(fā)者在不聲明throws子句的情況下拋出checked異常,下面就來詳細(xì)的了解一下,感興趣的可以了解一下2025-10-10

