Springboot整合lotdb ,详细源码

最近接到一个项目,是要使用springboot 整合lotdb 来处理大量的数据
相关使用记录:

这里使用了lotdb 数据库中的session ,具体jdbc 可以参照lotdb 的开发文档。

在使用之前要启动lotdb 服务
相关操作如下:

  1. 进入解压文件的sbin 目录
  2. 进入shell 操作
  3. 找到自己的对应的指令
    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

在这里插入图片描述

  1. 新建配置类
    在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;
    }
}

  1. 手写相关服务
    以设置存储组为例:
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();
        }
    }
}

  1. 写控制器
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";
    }
}

  1. 结果
    在这里插入图片描述
  2. 源码,欢迎star
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值