V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wizzer
V2EX  ›  数据库

TDengine 时序数据库的 NutzBoot 开发实例

  •  
  •   wizzer · 2021-03-24 11:24:31 +08:00 · 1190 次点击
    这是一个创建于 1343 天前的主题,其中的信息可能已经有所发展或是发生改变。

    nutz 及 nutzboot 已支持 TDengine

    基于 nutzboot 开发 TDengine 实例

    开发环境

    • 服务端:CentOS 8.2 64 位

    • 客户端:Windows 10 64 位

    TDengine 安装及配置

    • 官网下载 rpm 安装包

    • 执行安装 rpm -ivh TDengine-server-2.0.18.0-Linux-x64.rpm

    • 修改配置文件 vi /etc/taos/taos.cfg 加上当前服务器 hostname 主机名

    # first fully qualified domain name (FQDN) for TDengine system
    firstEp                   wizzer-test:6030
    # local fully qualified domain name (FQDN)
    fqdn                      wizzer-test
    
    
    • 若为默认密码则直接输入 taostaos -h 127.0.0.1 执行数据库创建命令
    taos > create database test;
    

    Windows 10 hosts 配置

    • 修改 C:\Windows\System32\drivers\etc\hosts

    • 添加 ip wizzer-test

    创建 nutzboot Maven 项目

    • pom.xml 文件加入 nutzboot 及 TDengine JDBC 依赖
    <?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>
    
        <groupId>com.budwk</groupId>
        <artifactId>test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <nutzboot.version>2.4.2-SNAPSHOT</nutzboot.version>
            <jaxb-api.version>2.3.1</jaxb-api.version>
            <slf4j.version>1.7.25</slf4j.version>
            <logback.version>1.2.3</logback.version>
            <taos-jdbcdriver.version>2.0.23</taos-jdbcdriver.version>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.nutz</groupId>
                <artifactId>nutzboot-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.nutz</groupId>
                <artifactId>nutzboot-starter-nutz-dao</artifactId>
            </dependency>
            <dependency>
                <groupId>org.nutz</groupId>
                <artifactId>nutzboot-starter-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>com.taosdata.jdbc</groupId>
                <artifactId>taos-jdbcdriver</artifactId>
                <version>${taos-jdbcdriver.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>${logback.version}</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${logback.version}</version>
            </dependency>
        </dependencies>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.nutz</groupId>
                    <artifactId>nutzboot-parent</artifactId>
                    <version>${nutzboot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <repositories>
            <repository>
                <id>nutz</id>
                <url>http://jfrog.nutz.cn/artifactory/libs-release</url>
            </repository>
            <repository>
                <id>nutz-snapshots</id>
                <url>http://jfrog.nutz.cn/artifactory/snapshots</url>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nutz-snapshots</id>
                <url>http://jfrog.nutz.cn/artifactory/snapshots</url>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
                <releases>
                    <enabled>false</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArgs>
                            <arg>-parameters</arg>
                        </compilerArgs>
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.nutz.boot</groupId>
                    <artifactId>nutzboot-maven-plugin</artifactId>
                    <version>${nutzboot.version}</version>
                </plugin>
            </plugins>
        </build>
    </project>
    
    • 创建实体类
    /**
     * 注意 TDengine 表及字段名都为小写字母
     */
    @Table("iot_dev")
    public class Iot_dev implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @Column
        @Comment("ID")
        @ColDefine(type = ColType.TIMESTAMP)
        private Date ts;
    
        @Column("devid") //字段名都为小写字母
        @Comment("设备 ID")
        @ColDefine(type = ColType.VARCHAR, width = 32)
        private String devId;
    
        @Column("devtype") //字段名都为小写字母
        @Comment("设备类型")
        @ColDefine(type = ColType.BINARY, width = 32)
        private String devType;
    
        @Column
        @Comment("状态")
        @ColDefine(type = ColType.BOOLEAN)
        private Boolean status;
    
        @Column
        @Comment("读数 1")
        @ColDefine(type = ColType.DOUBLE)
        private Double val1;
    
        @Column
        @Comment("读数 2")
        @ColDefine(type = ColType.INT)
        private Integer val2;
    
        @Column
        @Comment("读数 3")
        @ColDefine(type = ColType.INT,width = 3)
        private Integer val3;
    
        @Column
        @Comment("读数 4")
        @ColDefine(type = ColType.INT,width = 2)
        private Integer val4;
    
    }
    

    完整代码见

    https://gitee.com/wizzer/demo/tree/master/nutzboot-tdengine-demo

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3365 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 00:41 · PVG 08:41 · LAX 16:41 · JFK 19:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.