taosdata / TDengine

TDengine is an open source, high-performance, cloud native time-series database optimized for Internet of Things (IoT), Connected Cars, Industrial IoT and DevOps.

Home Page:https://tdengine.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

【求助 】使用 schemaless 写入超级表 运行SchemalessWsTest.java报错

JJiacheng opened this issue · comments

具体报错信息如下: [WebSocketConnectReadThread-12] DEBUG com.taosdata.jdbc.ws.WSClient - disconnect uri: ws://127.0.0.1:6041/ws, code : 1002 , reason: Invalid status code received: 404 Status line: HTTP/1.1 404 Not Found, remote: false
Exception in thread "main" java.sql.SQLException: ERROR (0x231d): can't create connection with server within: 60000 milliseconds

本地docker 搭建的 tdengine 版本号3.1.1.0

taos-jdbcdriver版本 3.2.11

package com.alibaba.datax.plugin.writer.tdengine30writer;

import com.taosdata.jdbc.AbstractConnection;
import com.taosdata.jdbc.SchemalessWriter;
import com.taosdata.jdbc.enums.SchemalessProtocolType;
import com.taosdata.jdbc.enums.SchemalessTimestampType;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

// ANCHOR: schemaless
public class LineProtocolExample {
private static final String host = "127.0.0.1";
private static final String lineDemo = "meters,groupid=2,location=California.SanFrancisco current=10.3000002f64,voltage=219i32,phase=0.31f64 1626006833639000000";
private static final String telnetDemo = "stb0_0 1707095283260 4 host=host0 interface=eth0";
private static final String jsonDemo = "{"metric": "meter_current","timestamp": 1626846400,"value": 10.3, "tags": {"groupid": 2, "location": "California.SanFrancisco", "id": "d1001"}}";

public static void main(String[] args) throws SQLException {
    final String url = "jdbc:TAOS-RS://" + host + ":6041/power?user=root&password=taosdata&batchfetch=true";
    try(Connection connection = DriverManager.getConnection(url)){
        init(connection);
        SchemalessWriter writer = new SchemalessWriter(connection);

        writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS);
        writer.write(telnetDemo, SchemalessProtocolType.TELNET, SchemalessTimestampType.MILLI_SECONDS);
        writer.write(jsonDemo, SchemalessProtocolType.JSON, SchemalessTimestampType.SECONDS);
    }
}

private static void init(Connection connection) throws SQLException {
    try (Statement stmt = connection.createStatement()) {
        stmt.execute("CREATE DATABASE IF NOT EXISTS power");
        stmt.execute("USE power");
    }
}

}
// ANCHOR_END: schemaless

image tdengine 版本3.1.1.0直接用REST 连接batchfetch 参数并设置为 true,开启 WebSocket 连接 不支持吧