使用Session原生IotDB
parent
53311e2f98
commit
7e77b4c0c0
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-common-iotdb</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,18 @@
|
|||
//package com.muyu.common.iotdb;
|
||||
//
|
||||
//import org.springframework.boot.SpringApplication;
|
||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
//
|
||||
///**
|
||||
// * @Author: 胡杨
|
||||
// * @Name: CloudSystemSaas
|
||||
// * @Description: SaaS系统驱动器
|
||||
// * @CreatedDate: 2024/9/22 上午10:05
|
||||
// * @FilePath: com.muyu.system.saas
|
||||
// */
|
||||
//@SpringBootApplication
|
||||
//public class CloudIotDBApplication {
|
||||
// public static void main(String[] args) {
|
||||
// SpringApplication.run(CloudIotDBApplication.class, args);
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,32 @@
|
|||
//package com.muyu.common.iotdb;
|
||||
//
|
||||
//
|
||||
//import com.muyu.common.iotdb.config.IotDBConfig;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//
|
||||
///**
|
||||
// * 测试控制层
|
||||
// * @Author: 胡杨
|
||||
// * @Name: Test
|
||||
// * @Description:
|
||||
// * @CreatedDate: 2024/9/27 上午10:54
|
||||
// * @FilePath: com.muyu.data.processing.controller
|
||||
// */
|
||||
//@Slf4j
|
||||
//@RestController
|
||||
//@RequestMapping("/Test")
|
||||
//public class TestController {
|
||||
// @Resource
|
||||
// private IotDBConfig iotDBConfig;
|
||||
//
|
||||
// @GetMapping("/insertData")
|
||||
// public void insertData(String deviceId, long time, double value) throws Exception {
|
||||
// String sql = String.format("insert into root.one.%s(timestamp, temperature) values (%d, %f)", deviceId, time, value);
|
||||
// iotDBConfig.iotSession().executeNonQueryStatement(sql);
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.common.iotdb.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;
|
||||
|
||||
/**
|
||||
* 时序数据库配置
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: IotDBConfig
|
||||
* @Description: 时序数据库配置
|
||||
* @CreatedDate: 2024/9/29 下午9:30
|
||||
* @FilePath: com.muyu.data.processing.config
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class IotDBConfig {
|
||||
|
||||
@Value("${spring.iotdb.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${spring.iotdb.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${spring.iotdb.user}")
|
||||
private String user;
|
||||
|
||||
@Value("${spring.iotdb.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${spring.iotdb.fetchSize}")
|
||||
private int fetchSize;
|
||||
|
||||
@Bean
|
||||
public Session iotSession(){
|
||||
Session session = new Session(ip, port, user, password, fetchSize);
|
||||
try {
|
||||
session.open();
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.muyu.common.iotdb.config.IotDBConfig
|
|
@ -23,6 +23,7 @@
|
|||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-caffeine</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
<module>cloud-common-iotdb</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -37,6 +37,12 @@
|
|||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-iotdb</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -61,6 +67,11 @@
|
|||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
|
@ -74,47 +85,52 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-jdbc</artifactId>
|
||||
<version>0.12.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.20</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.5</version>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.iotdb</groupId>-->
|
||||
<!-- <artifactId>iotdb-session</artifactId>-->
|
||||
<!-- <version>1.3.2</version>-->
|
||||
<!-- <artifactId>iotdb-jdbc</artifactId>-->
|
||||
<!-- <version>0.12.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>1.2.20</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- Druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Dynamic DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
||||
<version>${dynamic-ds.version}</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.mybatis</groupId>-->
|
||||
<!-- <artifactId>mybatis-spring</artifactId>-->
|
||||
<!-- <version>3.0.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>mybatis-plus-boot-starter</artifactId>-->
|
||||
<!-- <version>3.5.5</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!--<!– <dependency>–>-->
|
||||
<!--<!– <groupId>org.apache.iotdb</groupId>–>-->
|
||||
<!--<!– <artifactId>iotdb-session</artifactId>–>-->
|
||||
<!--<!– <version>1.3.2</version>–>-->
|
||||
<!--<!– </dependency>–>-->
|
||||
|
||||
<!-- <!– Druid –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>druid-spring-boot-3-starter</artifactId>-->
|
||||
<!-- <version>${druid.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <!– Dynamic DataSource –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>-->
|
||||
<!-- <version>${dynamic-ds.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
//package com.muyu.data.processing.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;
|
||||
//
|
||||
///**
|
||||
// * 时序数据库配置
|
||||
// *
|
||||
// * @Author: 胡杨
|
||||
// * @Name: IotDBConfig
|
||||
// * @Description: 时序数据库配置
|
||||
// * @CreatedDate: 2024/9/29 下午9:30
|
||||
// * @FilePath: com.muyu.data.processing.config
|
||||
// */
|
||||
//
|
||||
//@Configuration
|
||||
//public class IotDBConfig {
|
||||
//
|
||||
// @Value("${spring.iotdb.ip}")
|
||||
// private String ip;
|
||||
//
|
||||
// @Value("${spring.iotdb.port}")
|
||||
// private int port;
|
||||
//
|
||||
// @Value("${spring.iotdb.user}")
|
||||
// private String user;
|
||||
//
|
||||
// @Value("${spring.iotdb.password}")
|
||||
// private String password;
|
||||
//
|
||||
// @Value("${spring.iotdb.fetchSize}")
|
||||
// private int fetchSize;
|
||||
//
|
||||
// @Bean
|
||||
// public Session iotSession(){
|
||||
// Session session = new Session(ip, port, user, password, fetchSize);
|
||||
// try {
|
||||
// session.open();
|
||||
// } catch (IoTDBConnectionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// return session;
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -2,6 +2,7 @@ package com.muyu.data.processing.controller;
|
|||
|
||||
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.common.iotdb.config.IotDBConfig;
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
import com.muyu.common.rabbit.constants.RabbitConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -27,8 +28,8 @@ public class TestController {
|
|||
private KafkaProducer<String,String> kafkaProducer;
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
// @Resource
|
||||
// private IotDBConfig iotDBConfig;
|
||||
@Resource
|
||||
private IotDBConfig iotDBConfig;
|
||||
|
||||
@GetMapping("/testKafka")
|
||||
public void sendMsg(@RequestParam("msg") String msg) {
|
||||
|
@ -81,9 +82,9 @@ public class TestController {
|
|||
});
|
||||
}
|
||||
|
||||
// @GetMapping("/insertData")
|
||||
// public void insertData(String deviceId, long time, double value) throws Exception {
|
||||
// String sql = String.format("insert into root.one.%s(timestamp, temperature) values (%d, %f)", deviceId, time, value);
|
||||
// iotDBConfig.iotSession().executeNonQueryStatement(sql);
|
||||
// }
|
||||
@GetMapping("/insertData")
|
||||
public void insertData(@RequestParam("deviceId") String deviceId, @RequestParam("time") long time, @RequestParam("value") double value) throws Exception {
|
||||
String sql = String.format("insert into root.one.%s(timestamp, temperature) values (%d, %f)", deviceId, time, value);
|
||||
iotDBConfig.iotSession().executeNonQueryStatement(sql);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@ nacos:
|
|||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
# iotdb:
|
||||
# ip: 47.116.173.119
|
||||
# port: 6667
|
||||
# user: root
|
||||
# password: root
|
||||
# fetchSize: 10000
|
||||
# maxActive: 10
|
||||
iotdb:
|
||||
ip: 47.116.173.119
|
||||
port: 6667
|
||||
user: root
|
||||
password: root
|
||||
fetchSize: 10000
|
||||
maxActive: 10
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
|
|
Loading…
Reference in New Issue