当前位置: 首页 > news >正文

Springboot整合IoTB

一、引入依赖

 <!--引入iotdb session依赖-->
<dependency><groupId>org.apache.iotdb</groupId><artifactId>iotdb-session</artifactId><version>1.3.2</version>
</dependency>

二、配置IotDB连接

iotdb:username: rootpassword: rootip: 192.168.56.10port: 6667#批量操作数量maxSize: 200

三、创建配置类

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;@Beanpublic 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;}
}

四、创建service和实现类

@Service
@RequiredArgsConstructor
public class IoTDBServiceImpl implements IoTDBService {private final IotDBSessionConf conf;@Overridepublic 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;}@Overridepublic 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;}
}

五、创建工具类

@RequiredArgsConstructor
public class IoTDBUtils {private final IoTDBService iotDBService;/*** 根据自定义SQL语句执行查询* @param sql* @return*/SessionDataSetWrapper executeQueryStatement(String sql) {return iotDBService.executeQueryStatement(sql);}/*** 根据时间区间执行查询数据* @param paths 时间序列* @param startTime 开始时间戳(包含)* @param endTime 结束时间戳(不包含)* @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 {// 测试连接@Testpublic void testInitSessionPool() {IotDBSessionConf conf = new IotDBSessionConf();SessionPool sessionPool = conf.initSessionPool();System.out.println(sessionPool.getVersion());}
}

http://www.dtcms.com/a/503601.html

相关文章:

  • 个人做网站哪种类型的网站好男生做男生网站在那看
  • 从 0 到 1 学 C 语言队列:链表底层实现(初始化 / 入队 / 出队 / 销毁),代码可直接复用!
  • 书店网站建设网站栏目结构软文营销的特点有哪些
  • 做个网站要多久做网站app要多少钱
  • 1. Linux 驱动开发前景
  • 深入理解进程生命周期:从 fork 到 exit 的完整旅程
  • 英维克(002837)-2025-10-19
  • 自助手机网站建站软件wordpress metaslider
  • PCIe协议之 Equalization篇 之 FIR 三抽头的三因子的理解
  • FFmpeg 基本API av_seek_frame函数内部调用流程分析
  • FFmpeg 基本API avcodec_send_packet函数内部调用流程分析
  • 手机建站网站常德营销型网站建设
  • Flutter 与原生混合编程
  • DevOps 与 部署入门:加速软件交付与运维的实践指南
  • 优化网站seo中山做百度网站的公司名称
  • 上海袜网站建设电商营业执照
  • 找到K个最接近的元素
  • Java中JDK、JRE、JVM概念
  • MySQL 表操作核心指南:CRUD 与进阶技巧
  • 网站开发个人总结网页设计与网站建设在线考试1
  • 算法笔记 05
  • 游戏科技网站杭州建设工程交易中心网站
  • 网站做推广要备案吗四川seo快速排名
  • 有关房地产开发建设的网站哪些网站可以接点私活做的
  • 有关应广单片机数据类型与ROM空间优化的一点看法
  • 【2026计算机毕业设计】基于Jsp的医疗设备及业务综合巡检系统
  • 个人业务技能提升如何助力:从“做事”到“成事”的跃迁之路
  • 我们需要的中文编程是什么样子的?
  • 那些网站可以接私活做做兼职有哪些网站
  • 绚星智慧科技斩获智享会三项大奖,领跑AI时代学习与发展赛道