docs: improve go and csharp example
This commit is contained in:
parent
b779770979
commit
daf6437f53
|
@ -3,6 +3,7 @@
|
|||
connect/bin
|
||||
influxdbLine/bin
|
||||
optsJSON/bin
|
||||
nativesml/bin
|
||||
optsTelnet/bin
|
||||
query/bin
|
||||
sqlInsert/bin
|
||||
|
@ -11,9 +12,12 @@ subscribe/bin
|
|||
wsConnect/bin
|
||||
wsInsert/bin
|
||||
wsQuery/bin
|
||||
wssml/bin
|
||||
wsStmt/bin
|
||||
wssubscribe/bin
|
||||
connect/obj
|
||||
influxdbLine/obj
|
||||
nativesml/obj
|
||||
optsJSON/obj
|
||||
optsTelnet/obj
|
||||
query/obj
|
||||
|
@ -23,4 +27,6 @@ subscribe/obj
|
|||
wsConnect/obj
|
||||
wsInsert/obj
|
||||
wsQuery/obj
|
||||
wssml/obj
|
||||
wsStmt/obj
|
||||
wssubscribe/obj
|
|
@ -8,26 +8,27 @@ namespace TDengineExample
|
|||
// ANCHOR: main
|
||||
static void Main(String[] args)
|
||||
{
|
||||
var connectionString = "host=127.0.0.1;port=6030;username=root;password=taosdata";
|
||||
try
|
||||
{
|
||||
// Connect to TDengine server using Native
|
||||
var builder = new ConnectionStringBuilder("host=localhost;port=6030;username=root;password=taosdata");
|
||||
var builder = new ConnectionStringBuilder(connectionString);
|
||||
// Open connection with using block, it will close the connection automatically
|
||||
using (var client = DbDriver.Open(builder))
|
||||
{
|
||||
Console.WriteLine("connected");
|
||||
Console.WriteLine("Connected to " + connectionString + " successfully.");
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to connect to " + connectionString + "; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to connect to " + connectionString + "; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ namespace TDengineExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj",
|
||||
"projectName": "nativesml",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/root/.nuget/packages/</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/root/.nuget/packages/</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.8.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="/root/.nuget/packages/" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -1,149 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net6.0": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "13.0.3"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
|
||||
"type": "package",
|
||||
"path": "newtonsoft.json/13.0.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"LICENSE.md",
|
||||
"README.md",
|
||||
"lib/net20/Newtonsoft.Json.dll",
|
||||
"lib/net20/Newtonsoft.Json.xml",
|
||||
"lib/net35/Newtonsoft.Json.dll",
|
||||
"lib/net35/Newtonsoft.Json.xml",
|
||||
"lib/net40/Newtonsoft.Json.dll",
|
||||
"lib/net40/Newtonsoft.Json.xml",
|
||||
"lib/net45/Newtonsoft.Json.dll",
|
||||
"lib/net45/Newtonsoft.Json.xml",
|
||||
"lib/net6.0/Newtonsoft.Json.dll",
|
||||
"lib/net6.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.xml",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.xml",
|
||||
"newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"newtonsoft.json.nuspec",
|
||||
"packageIcon.png"
|
||||
]
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"sha512": "dDX+Oex4I0X9yCalU0/YyUN0ecy+8X5xj6N8CoqeLrU6ICYDZgilSGQK9Fh3qmLobhGQvOJWwDpoO73rryHU5Q==",
|
||||
"type": "package",
|
||||
"path": "tdengine.connector/3.1.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
"docs/README.md",
|
||||
"image/logo.jpg",
|
||||
"lib/net45/TDengine.dll",
|
||||
"lib/net451/TDengine.dll",
|
||||
"lib/net5.0/TDengine.dll",
|
||||
"lib/net6.0/TDengine.dll",
|
||||
"lib/netstandard2.0/TDengine.dll",
|
||||
"lib/netstandard2.1/TDengine.dll",
|
||||
"tdengine.connector.3.1.3.nupkg.sha512",
|
||||
"tdengine.connector.nuspec"
|
||||
]
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"net6.0": [
|
||||
"TDengine.Connector >= 3.1.*"
|
||||
]
|
||||
},
|
||||
"packageFolders": {
|
||||
"/root/.nuget/packages/": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj",
|
||||
"projectName": "nativesml",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "xbVzGVQru/qLTE5UBOQoTSR5C+6GFj/M4fcB1h/3W6PsWOVoFQLbV4fwAAKt5f5BKxrV1phiwzm2zGYK0fpXBQ==",
|
||||
"success": true,
|
||||
"projectFilePath": "/mnt/e/github/TDengine/docs/examples/csharp/nativesml/nativesml.csproj",
|
||||
"expectedPackageFiles": [
|
||||
"/root/.nuget/packages/newtonsoft.json/13.0.3/newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"/root/.nuget/packages/tdengine.connector/3.1.3/tdengine.connector.3.1.3.nupkg.sha512"
|
||||
],
|
||||
"logs": []
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
"restore":{"projectUniqueName":"E:\\github\\TDengine\\docs\\examples\\csharp\\nativesml\\nativesml.csproj","projectName":"nativesml","projectPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\nativesml\\nativesml.csproj","outputPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\nativesml\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net6.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"E:\\github\\taos-connector-dotnet\\src\\resource":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net6.0":{"targetAlias":"net6.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net6.0":{"targetAlias":"net6.0","dependencies":{"TDengine.Connector":{"target":"Package","version":"[3.1.*, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202\\RuntimeIdentifierGraph.json"}}
|
|
@ -1 +0,0 @@
|
|||
17225691407520754
|
|
@ -1 +0,0 @@
|
|||
17225689181017775
|
|
@ -42,13 +42,13 @@ namespace TDengineExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: main
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace TDengineExample
|
|||
CreateDatabaseAndTable(client);
|
||||
InsertData(client);
|
||||
QueryData(client);
|
||||
QueryWithReqId(client);
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
|
@ -49,13 +50,13 @@ namespace TDengineExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create db and table; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create db and table; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: create_db_and_table
|
||||
|
@ -77,18 +78,18 @@ namespace TDengineExample
|
|||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 218, 0.25000) ";
|
||||
var affectedRows = client.Exec(insertQuery);
|
||||
Console.WriteLine("inserted into " + affectedRows + " rows to power.meters successfully.");
|
||||
Console.WriteLine("insert " + affectedRows + " rows to power.meters successfully.");
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data to power.meters; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data to power.meters; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: insert_data
|
||||
|
@ -96,7 +97,7 @@ namespace TDengineExample
|
|||
|
||||
private static void QueryData(ITDengineClient client)
|
||||
{
|
||||
// ANCHOR: query_data
|
||||
// ANCHOR: select_data
|
||||
try
|
||||
{
|
||||
// query data
|
||||
|
@ -108,23 +109,59 @@ namespace TDengineExample
|
|||
var ts = (DateTime)rows.GetValue(0);
|
||||
var current = (float)rows.GetValue(1);
|
||||
var location = Encoding.UTF8.GetString((byte[])rows.GetValue(2));
|
||||
Console.WriteLine($"ts: {ts:yyyy-MM-dd HH:mm:ss.fff}, current: {current}, location: {location}");
|
||||
Console.WriteLine(
|
||||
$"ts: {ts:yyyy-MM-dd HH:mm:ss.fff}, current: {current}, location: {location}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to query data from power.meters; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to query data from power.meters; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: query_data
|
||||
// ANCHOR_END: select_data
|
||||
}
|
||||
|
||||
private static void QueryWithReqId(ITDengineClient client)
|
||||
{
|
||||
// ANCHOR: query_id
|
||||
try
|
||||
{
|
||||
// query data
|
||||
var query = "SELECT ts, current, location FROM power.meters limit 1";
|
||||
// query with request id 3
|
||||
using (var rows = client.Query(query,3))
|
||||
{
|
||||
while (rows.Read())
|
||||
{
|
||||
var ts = (DateTime)rows.GetValue(0);
|
||||
var current = (float)rows.GetValue(1);
|
||||
var location = Encoding.UTF8.GetString((byte[])rows.GetValue(2));
|
||||
Console.WriteLine(
|
||||
$"ts: {ts:yyyy-MM-dd HH:mm:ss.fff}, current: {current}, location: {location}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine("Failed to execute sql with reqId; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine("Failed to execute sql with reqId; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: query_id
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,13 +61,13 @@ namespace TDengineExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert to table meters using stmt; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert to table meters using stmt; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ namespace TMQExample
|
|||
{ "msg.with.table.name", "true" },
|
||||
{ "enable.auto.commit", "true" },
|
||||
{ "auto.commit.interval.ms", "1000" },
|
||||
{ "group.id", "group2" },
|
||||
{ "client.id", "1" },
|
||||
{ "group.id", "group1" },
|
||||
{ "client.id", "client1" },
|
||||
{ "td.connect.ip", "127.0.0.1" },
|
||||
{ "td.connect.user", "root" },
|
||||
{ "td.connect.pass", "taosdata" },
|
||||
|
@ -86,13 +86,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create consumer; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create consumer; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ namespace TMQExample
|
|||
{
|
||||
// handle message
|
||||
Console.WriteLine(
|
||||
$"message {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"data {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"{message.Value["current"]}, {message.Value["voltage"]}, {message.Value["phase"]}}}");
|
||||
}
|
||||
}
|
||||
|
@ -126,13 +126,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to poll data; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to poll data; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: subscribe
|
||||
|
@ -150,17 +150,35 @@ namespace TMQExample
|
|||
{
|
||||
consumer.Seek(new TopicPartitionOffset(topicPartition.Topic, topicPartition.Partition, 0));
|
||||
}
|
||||
Console.WriteLine("assignment seek to beginning successfully");
|
||||
// poll data again
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
// consume message with using block to ensure the result is disposed
|
||||
using (var cr = consumer.Consume(100))
|
||||
{
|
||||
if (cr == null) continue;
|
||||
foreach (var message in cr.Message)
|
||||
{
|
||||
// handle message
|
||||
Console.WriteLine(
|
||||
$"second data polled: {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"{message.Value["current"]}, {message.Value["voltage"]}, {message.Value["phase"]}}}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to seek; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to seek; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: seek
|
||||
|
@ -187,13 +205,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to commit offset; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to commit offset; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -207,21 +225,24 @@ namespace TMQExample
|
|||
{
|
||||
// unsubscribe
|
||||
consumer.Unsubscribe();
|
||||
// close consumer
|
||||
consumer.Close();
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to unsubscribe consumer; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to unsubscribe consumer; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// close consumer
|
||||
consumer.Close();
|
||||
}
|
||||
// ANCHOR_END: close
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,27 +9,29 @@ namespace Examples
|
|||
// ANCHOR: main
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var connectionString =
|
||||
"protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata";
|
||||
try
|
||||
{
|
||||
// Connect to TDengine server using WebSocket
|
||||
var builder = new ConnectionStringBuilder(
|
||||
"protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata");
|
||||
var builder = new ConnectionStringBuilder(connectionString);
|
||||
// Open connection with using block, it will close the connection automatically
|
||||
using (var client = DbDriver.Open(builder))
|
||||
{
|
||||
Console.WriteLine("connected");
|
||||
Console.WriteLine("Connected to " + connectionString + " successfully.");
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to connect to " + connectionString + "; ErrCode:" + e.Code +
|
||||
"; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to connect to " + connectionString + "; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,13 +50,13 @@ namespace Examples
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create db and table; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create db and table; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: create_db_and_table
|
||||
|
@ -78,18 +78,18 @@ namespace Examples
|
|||
"VALUES " +
|
||||
"(NOW + 1a, 10.30000, 218, 0.25000) ";
|
||||
var affectedRows = client.Exec(insertQuery);
|
||||
Console.WriteLine("inserted " + affectedRows + " rows to power.meters successfully.");
|
||||
Console.WriteLine("insert " + affectedRows + " rows to power.meters successfully.");
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data to power.meters; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data to power.meters; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: insert_data
|
||||
|
@ -117,13 +117,13 @@ namespace Examples
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to query data from power.meters; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to query data from power.meters; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: select_data
|
||||
|
@ -136,8 +136,8 @@ namespace Examples
|
|||
{
|
||||
// query data
|
||||
var query = "SELECT ts, current, location FROM power.meters limit 1";
|
||||
// query with request id 1
|
||||
using (var rows = client.Query(query,1))
|
||||
// query with request id 3
|
||||
using (var rows = client.Query(query,3))
|
||||
{
|
||||
while (rows.Read())
|
||||
{
|
||||
|
@ -152,13 +152,13 @@ namespace Examples
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to execute sql with reqId; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to execute sql with reqId; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: query_id
|
||||
|
|
|
@ -62,13 +62,13 @@ namespace Examples
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert to table meters using stmt; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert to table meters using stmt; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ namespace TDengineExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to insert data with schemaless; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net6.0": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "13.0.3"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
|
||||
"type": "package",
|
||||
"path": "newtonsoft.json/13.0.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"LICENSE.md",
|
||||
"README.md",
|
||||
"lib/net20/Newtonsoft.Json.dll",
|
||||
"lib/net20/Newtonsoft.Json.xml",
|
||||
"lib/net35/Newtonsoft.Json.dll",
|
||||
"lib/net35/Newtonsoft.Json.xml",
|
||||
"lib/net40/Newtonsoft.Json.dll",
|
||||
"lib/net40/Newtonsoft.Json.xml",
|
||||
"lib/net45/Newtonsoft.Json.dll",
|
||||
"lib/net45/Newtonsoft.Json.xml",
|
||||
"lib/net6.0/Newtonsoft.Json.dll",
|
||||
"lib/net6.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.xml",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.xml",
|
||||
"newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"newtonsoft.json.nuspec",
|
||||
"packageIcon.png"
|
||||
]
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"sha512": "dDX+Oex4I0X9yCalU0/YyUN0ecy+8X5xj6N8CoqeLrU6ICYDZgilSGQK9Fh3qmLobhGQvOJWwDpoO73rryHU5Q==",
|
||||
"type": "package",
|
||||
"path": "tdengine.connector/3.1.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
"docs/README.md",
|
||||
"image/logo.jpg",
|
||||
"lib/net45/TDengine.dll",
|
||||
"lib/net451/TDengine.dll",
|
||||
"lib/net5.0/TDengine.dll",
|
||||
"lib/net6.0/TDengine.dll",
|
||||
"lib/netstandard2.0/TDengine.dll",
|
||||
"lib/netstandard2.1/TDengine.dll",
|
||||
"tdengine.connector.3.1.3.nupkg.sha512",
|
||||
"tdengine.connector.nuspec"
|
||||
]
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"net6.0": [
|
||||
"TDengine.Connector >= 3.1.*"
|
||||
]
|
||||
},
|
||||
"packageFolders": {
|
||||
"/root/.nuget/packages/": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj",
|
||||
"projectName": "wssml",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "f/iAhsDLFU7jI95wf6NFa1XHue7HQsgzzqr1jqfMTnrejkprbps/2toSr4j9kUyRUVdJNr7/TtdHhEsxEhKo+A==",
|
||||
"success": true,
|
||||
"projectFilePath": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj",
|
||||
"expectedPackageFiles": [
|
||||
"/root/.nuget/packages/newtonsoft.json/13.0.3/newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"/root/.nuget/packages/tdengine.connector/3.1.3/tdengine.connector.3.1.3.nupkg.sha512"
|
||||
],
|
||||
"logs": []
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
"restore":{"projectUniqueName":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssml\\wssml.csproj","projectName":"wssml","projectPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssml\\wssml.csproj","outputPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssml\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net6.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"E:\\github\\taos-connector-dotnet\\src\\resource":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net6.0":{"targetAlias":"net6.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net6.0":{"targetAlias":"net6.0","dependencies":{"TDengine.Connector":{"target":"Package","version":"[3.1.*, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202\\RuntimeIdentifierGraph.json"}}
|
|
@ -1 +0,0 @@
|
|||
17225691310239873
|
|
@ -1 +0,0 @@
|
|||
17225689180359712
|
|
@ -1,67 +0,0 @@
|
|||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj",
|
||||
"projectName": "wssml",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/wssml.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssml/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/root/.nuget/packages/</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/root/.nuget/packages/</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.8.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="/root/.nuget/packages/" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -72,8 +72,8 @@ namespace TMQExample
|
|||
{ "msg.with.table.name", "true" },
|
||||
{ "enable.auto.commit", "true" },
|
||||
{ "auto.commit.interval.ms", "1000" },
|
||||
{ "group.id", "group2" },
|
||||
{ "client.id", "1" },
|
||||
{ "group.id", "group1" },
|
||||
{ "client.id", "client1" },
|
||||
{ "td.connect.ip", "127.0.0.1" },
|
||||
{ "td.connect.user", "root" },
|
||||
{ "td.connect.pass", "taosdata" },
|
||||
|
@ -87,13 +87,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create consumer; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to create consumer; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ namespace TMQExample
|
|||
{
|
||||
// handle message
|
||||
Console.WriteLine(
|
||||
$"message {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"data {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"{message.Value["current"]}, {message.Value["voltage"]}, {message.Value["phase"]}}}");
|
||||
}
|
||||
}
|
||||
|
@ -127,13 +127,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to poll data; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to poll data; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: subscribe
|
||||
|
@ -151,17 +151,35 @@ namespace TMQExample
|
|||
{
|
||||
consumer.Seek(new TopicPartitionOffset(topicPartition.Topic, topicPartition.Partition, 0));
|
||||
}
|
||||
Console.WriteLine("assignment seek to beginning successfully");
|
||||
// poll data again
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
// consume message with using block to ensure the result is disposed
|
||||
using (var cr = consumer.Consume(100))
|
||||
{
|
||||
if (cr == null) continue;
|
||||
foreach (var message in cr.Message)
|
||||
{
|
||||
// handle message
|
||||
Console.WriteLine(
|
||||
$"second data polled: {{{((DateTime)message.Value["ts"]).ToString("yyyy-MM-dd HH:mm:ss.fff")}, " +
|
||||
$"{message.Value["current"]}, {message.Value["voltage"]}, {message.Value["phase"]}}}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to seek; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to seek; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
// ANCHOR_END: seek
|
||||
|
@ -188,13 +206,13 @@ namespace TMQExample
|
|||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to commit offset; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to commit offset; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -208,21 +226,24 @@ namespace TMQExample
|
|||
{
|
||||
// unsubscribe
|
||||
consumer.Unsubscribe();
|
||||
// close consumer
|
||||
consumer.Close();
|
||||
}
|
||||
catch (TDengineError e)
|
||||
{
|
||||
// handle TDengine error
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to unsubscribe consumer; ErrCode:" + e.Code + "; ErrMessage: " + e.Error);
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// handle other exceptions
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine("Failed to unsubscribe consumer; Err:" + e.Message);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// close consumer
|
||||
consumer.Close();
|
||||
}
|
||||
// ANCHOR_END: close
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net6.0": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/Newtonsoft.Json.dll": {
|
||||
"related": ".xml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "13.0.3"
|
||||
},
|
||||
"compile": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
},
|
||||
"runtime": {
|
||||
"lib/net6.0/TDengine.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"Newtonsoft.Json/13.0.3": {
|
||||
"sha512": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
|
||||
"type": "package",
|
||||
"path": "newtonsoft.json/13.0.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
".signature.p7s",
|
||||
"LICENSE.md",
|
||||
"README.md",
|
||||
"lib/net20/Newtonsoft.Json.dll",
|
||||
"lib/net20/Newtonsoft.Json.xml",
|
||||
"lib/net35/Newtonsoft.Json.dll",
|
||||
"lib/net35/Newtonsoft.Json.xml",
|
||||
"lib/net40/Newtonsoft.Json.dll",
|
||||
"lib/net40/Newtonsoft.Json.xml",
|
||||
"lib/net45/Newtonsoft.Json.dll",
|
||||
"lib/net45/Newtonsoft.Json.xml",
|
||||
"lib/net6.0/Newtonsoft.Json.dll",
|
||||
"lib/net6.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.0/Newtonsoft.Json.xml",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.dll",
|
||||
"lib/netstandard1.3/Newtonsoft.Json.xml",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.dll",
|
||||
"lib/netstandard2.0/Newtonsoft.Json.xml",
|
||||
"newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"newtonsoft.json.nuspec",
|
||||
"packageIcon.png"
|
||||
]
|
||||
},
|
||||
"TDengine.Connector/3.1.3": {
|
||||
"sha512": "dDX+Oex4I0X9yCalU0/YyUN0ecy+8X5xj6N8CoqeLrU6ICYDZgilSGQK9Fh3qmLobhGQvOJWwDpoO73rryHU5Q==",
|
||||
"type": "package",
|
||||
"path": "tdengine.connector/3.1.3",
|
||||
"files": [
|
||||
".nupkg.metadata",
|
||||
"docs/README.md",
|
||||
"image/logo.jpg",
|
||||
"lib/net45/TDengine.dll",
|
||||
"lib/net451/TDengine.dll",
|
||||
"lib/net5.0/TDengine.dll",
|
||||
"lib/net6.0/TDengine.dll",
|
||||
"lib/netstandard2.0/TDengine.dll",
|
||||
"lib/netstandard2.1/TDengine.dll",
|
||||
"tdengine.connector.3.1.3.nupkg.sha512",
|
||||
"tdengine.connector.nuspec"
|
||||
]
|
||||
}
|
||||
},
|
||||
"projectFileDependencyGroups": {
|
||||
"net6.0": [
|
||||
"TDengine.Connector >= 3.1.*"
|
||||
]
|
||||
},
|
||||
"packageFolders": {
|
||||
"/root/.nuget/packages/": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj",
|
||||
"projectName": "wssubscribe",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )",
|
||||
"generatePathProperty": true
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "iYS3B811DdocWqUXN2aMJdEwvfDVCixB5mK4XYN+98yFFNdPOU8hN4wQCxaOSFM7xKpvlmJvQPwkMetGBbFO8g==",
|
||||
"success": true,
|
||||
"projectFilePath": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj",
|
||||
"expectedPackageFiles": [
|
||||
"/root/.nuget/packages/newtonsoft.json/13.0.3/newtonsoft.json.13.0.3.nupkg.sha512",
|
||||
"/root/.nuget/packages/tdengine.connector/3.1.3/tdengine.connector.3.1.3.nupkg.sha512"
|
||||
],
|
||||
"logs": []
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
"restore":{"projectUniqueName":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssubscribe\\wssubscribe.csproj","projectName":"wssubscribe","projectPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssubscribe\\wssubscribe.csproj","outputPath":"E:\\github\\TDengine\\docs\\examples\\csharp\\wssubscribe\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net6.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"E:\\github\\taos-connector-dotnet\\src\\resource":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net6.0":{"targetAlias":"net6.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net6.0":{"targetAlias":"net6.0","dependencies":{"TDengine.Connector":{"target":"Package","version":"[3.1.*, )","generatePathProperty":true}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202\\RuntimeIdentifierGraph.json"}}
|
|
@ -1 +0,0 @@
|
|||
17225691490262111
|
|
@ -1 +0,0 @@
|
|||
17225689180408669
|
|
@ -1,68 +0,0 @@
|
|||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj",
|
||||
"projectName": "wssubscribe",
|
||||
"projectPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/wssubscribe.csproj",
|
||||
"packagesPath": "/root/.nuget/packages/",
|
||||
"outputPath": "/mnt/e/github/TDengine/docs/examples/csharp/wssubscribe/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/root/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net6.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net6.0": {
|
||||
"targetAlias": "net6.0",
|
||||
"dependencies": {
|
||||
"TDengine.Connector": {
|
||||
"target": "Package",
|
||||
"version": "[3.1.*, )",
|
||||
"generatePathProperty": true
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/root/.dotnet/sdk/8.0.100/RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/root/.nuget/packages/</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/root/.nuget/packages/</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.8.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="/root/.nuget/packages/" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<PkgTDengine_Connector Condition=" '$(PkgTDengine_Connector)' == '' ">/root/.nuget/packages/tdengine.connector/3.1.3</PkgTDengine_Connector>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -7,6 +7,6 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.1.*" GeneratePathProperty="true" />
|
||||
<PackageReference Include="TDengine.Connector" Version="3.1.3" GeneratePathProperty="true" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -16,8 +16,7 @@ func main() {
|
|||
taos, err := sql.Open("taosSql", taosDSN)
|
||||
if err != nil {
|
||||
log.Fatalln("failed to connect TDengine, err:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Connected")
|
||||
fmt.Println("Connected to " + taosDSN + " successfully.")
|
||||
defer taos.Close()
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ func main() {
|
|||
taos, err := sql.Open("taosSql", taosDSN)
|
||||
if err != nil {
|
||||
log.Fatalln("failed to connect TDengine, err:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Connected")
|
||||
defer taos.Close()
|
||||
|
|
|
@ -16,8 +16,7 @@ func main() {
|
|||
taos, err := sql.Open("taosRestful", taosDSN)
|
||||
if err != nil {
|
||||
log.Fatalln("failed to connect TDengine, err:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Connected")
|
||||
fmt.Println("Connected to " + taosDSN + " successfully.")
|
||||
defer taos.Close()
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ func main() {
|
|||
taos, err := sql.Open("taosWS", taosDSN)
|
||||
if err != nil {
|
||||
log.Fatalln("failed to connect TDengine, err:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Connected")
|
||||
fmt.Println("Connected to " + taosDSN + " successfully.")
|
||||
defer taos.Close()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/taosdata/driver-go/v3/taosSql"
|
||||
|
@ -12,7 +13,7 @@ import (
|
|||
func main() {
|
||||
db, err := sql.Open("taosSql", "root:taosdata@tcp(localhost:6030)/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Open database error: ", err)
|
||||
}
|
||||
defer db.Close()
|
||||
initEnv(db)
|
||||
|
@ -22,7 +23,7 @@ func main() {
|
|||
// execute query with context
|
||||
rows, err := db.QueryContext(ctx, "SELECT ts, current, location FROM power.meters limit 1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Query error: ", err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
|
@ -32,7 +33,7 @@ func main() {
|
|||
)
|
||||
err = rows.Scan(&ts, ¤t, &location)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Scan error: ", err)
|
||||
}
|
||||
fmt.Printf("ts: %s, current: %f, location: %s\n", ts, current, location)
|
||||
}
|
||||
|
@ -42,14 +43,14 @@ func main() {
|
|||
func initEnv(conn *sql.DB) {
|
||||
_, err := conn.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Create database error: ", err)
|
||||
}
|
||||
_, err = conn.Exec("CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Create table error: ", err)
|
||||
}
|
||||
_, err = conn.Exec("INSERT INTO power.d1001 USING power.meters TAGS (2, 'California.SanFrancisco') VALUES (NOW , 10.2, 219, 0.32)")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("Insert data error: ", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/taosdata/driver-go/v3/af"
|
||||
)
|
||||
|
||||
|
@ -12,30 +14,30 @@ func main() {
|
|||
|
||||
conn, err := af.Open(host, "root", "taosdata", "", 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
_, err = conn.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
_, err = conn.Exec("USE power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to use database, err:", err)
|
||||
}
|
||||
// insert influxdb line protocol
|
||||
err = conn.InfluxDBInsertLines([]string{lineDemo}, "ms")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert influxdb line protocol, err:", err)
|
||||
}
|
||||
// insert opentsdb telnet protocol
|
||||
err = conn.OpenTSDBInsertTelnetLines([]string{telnetDemo})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert opentsdb telnet line protocol, err:", err)
|
||||
}
|
||||
// insert opentsdb json protocol
|
||||
err = conn.OpenTSDBInsertJsonPayload(jsonDemo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert opentsdb json format protocol, err:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ func main() {
|
|||
|
||||
db, err := sql.Open("taosWS", fmt.Sprintf("root:taosdata@ws(%s:6041)/", host))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
_, err = db.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
s, err := schemaless.NewSchemaless(schemaless.NewConfig("ws://localhost:6041", 1,
|
||||
schemaless.SetDb("power"),
|
||||
|
@ -32,26 +32,23 @@ func main() {
|
|||
schemaless.SetWriteTimeout(10*time.Second),
|
||||
schemaless.SetUser("root"),
|
||||
schemaless.SetPassword("taosdata"),
|
||||
schemaless.SetErrorHandler(func(err error) {
|
||||
log.Fatal(err)
|
||||
}),
|
||||
))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create schemaless connection, err:", err)
|
||||
}
|
||||
// insert influxdb line protocol
|
||||
err = s.Insert(lineDemo, schemaless.InfluxDBLineProtocol, "ms", 0, common.GetReqID())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert influxdb line protocol, err:", err)
|
||||
}
|
||||
// insert opentsdb telnet line protocol
|
||||
err = s.Insert(telnetDemo, schemaless.OpenTSDBTelnetLineProtocol, "ms", 0, common.GetReqID())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert opentsdb telnet line protocol, err:", err)
|
||||
}
|
||||
// insert opentsdb json format protocol
|
||||
err = s.Insert(jsonDemo, schemaless.OpenTSDBJsonFormatProtocol, "s", 0, common.GetReqID())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert opentsdb json format protocol, err:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/taosdata/driver-go/v3/taosSql"
|
||||
|
@ -11,35 +12,35 @@ import (
|
|||
func main() {
|
||||
db, err := sql.Open("taosSql", "root:taosdata@tcp(localhost:6030)/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("open database failed:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
// ANCHOR: create_db_and_table
|
||||
// create database
|
||||
res, err := db.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("create database failed:", err)
|
||||
}
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("get affected rows failed:", err)
|
||||
}
|
||||
fmt.Println("create database affected:", affected)
|
||||
// use database
|
||||
res, err = db.Exec("USE power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("use database failed:", err)
|
||||
}
|
||||
affected, err = res.RowsAffected()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("get affected rows failed:", err)
|
||||
}
|
||||
fmt.Println("use database affected:", affected)
|
||||
// create table
|
||||
res, err = db.Exec("CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
affected, err = res.RowsAffected()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("create table failed:", err)
|
||||
}
|
||||
fmt.Println("create table affected:", affected)
|
||||
// ANCHOR_END: create_db_and_table
|
||||
|
@ -56,11 +57,11 @@ func main() {
|
|||
"(NOW + 1a, 10.30000, 218, 0.25000) "
|
||||
res, err = db.Exec(insertQuery)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("insert data failed:", err)
|
||||
}
|
||||
affected, err = res.RowsAffected()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("get affected rows failed:", err)
|
||||
}
|
||||
// you can check affectedRows here
|
||||
fmt.Println("insert data affected:", affected)
|
||||
|
@ -69,7 +70,7 @@ func main() {
|
|||
// query data, make sure the database and table are created before
|
||||
rows, err := db.Query("SELECT ts, current, location FROM power.meters limit 100")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("query data failed:", err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
|
@ -79,7 +80,7 @@ func main() {
|
|||
)
|
||||
err = rows.Scan(&ts, ¤t, &location)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("scan data failed:", err)
|
||||
}
|
||||
// you can check data here
|
||||
fmt.Printf("ts: %s, current: %f, location: %s\n", ts, current, location)
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -16,28 +17,28 @@ func main() {
|
|||
numOfRow := 10
|
||||
db, err := af.Open(host, "root", "taosdata", "", 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
// prepare database and table
|
||||
_, err = db.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
_, err = db.Exec("USE power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to use database, err:", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE STABLE IF NOT EXISTS meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create table, err:", err)
|
||||
}
|
||||
// prepare statement
|
||||
sql := "INSERT INTO ? USING meters TAGS(?,?) VALUES (?,?,?,?)"
|
||||
stmt := db.Stmt()
|
||||
err = stmt.Prepare(sql)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to prepare statement, err:", err)
|
||||
}
|
||||
for i := 1; i <= numOfSubTable; i++ {
|
||||
tableName := fmt.Sprintf("d_bind_%d", i)
|
||||
|
@ -45,7 +46,7 @@ func main() {
|
|||
// set tableName and tags
|
||||
err = stmt.SetTableNameWithTags(tableName, tags)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to set table name and tags, err:", err)
|
||||
}
|
||||
// bind column data
|
||||
current := time.Now()
|
||||
|
@ -57,18 +58,18 @@ func main() {
|
|||
AddFloat(rand.Float32())
|
||||
err = stmt.BindRow(row)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to bind row, err:", err)
|
||||
}
|
||||
}
|
||||
// add batch
|
||||
err = stmt.AddBatch()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to add batch, err:", err)
|
||||
}
|
||||
// execute batch
|
||||
err = stmt.Execute()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to execute batch, err:", err)
|
||||
}
|
||||
// get affected rows
|
||||
affected := stmt.GetAffectedRows()
|
||||
|
@ -77,6 +78,6 @@ func main() {
|
|||
}
|
||||
err = stmt.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to close statement, err:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -18,17 +19,17 @@ func main() {
|
|||
numOfRow := 10
|
||||
db, err := sql.Open("taosRestful", fmt.Sprintf("root:taosdata@http(%s:6041)/", host))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
// prepare database and table
|
||||
_, err = db.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create table, err:", err)
|
||||
}
|
||||
|
||||
config := stmt.NewConfig(fmt.Sprintf("ws://%s:6041", host), 0)
|
||||
|
@ -40,17 +41,17 @@ func main() {
|
|||
|
||||
connector, err := stmt.NewConnector(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create stmt connector, err:", err)
|
||||
}
|
||||
// // prepare statement
|
||||
// prepare statement
|
||||
sql := "INSERT INTO ? USING meters TAGS(?,?) VALUES (?,?,?,?)"
|
||||
stmt, err := connector.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to init stmt, err:", err)
|
||||
}
|
||||
err = stmt.Prepare(sql)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to prepare stmt, err:", err)
|
||||
}
|
||||
for i := 1; i <= numOfSubTable; i++ {
|
||||
tableName := fmt.Sprintf("d_bind_%d", i)
|
||||
|
@ -60,12 +61,12 @@ func main() {
|
|||
// set tableName
|
||||
err = stmt.SetTableName(tableName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to set table name, err:", err)
|
||||
}
|
||||
// set tags
|
||||
err = stmt.SetTags(tags, tagsType)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to set tags, err:", err)
|
||||
}
|
||||
// bind column data
|
||||
current := time.Now()
|
||||
|
@ -77,18 +78,18 @@ func main() {
|
|||
columnData[3] = param.NewParam(1).AddFloat(rand.Float32())
|
||||
err = stmt.BindParam(columnData, columnType)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to bind param, err:", err)
|
||||
}
|
||||
}
|
||||
// add batch
|
||||
err = stmt.AddBatch()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to add batch, err:", err)
|
||||
}
|
||||
// execute batch
|
||||
err = stmt.Exec()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to exec stmt, err:", err)
|
||||
}
|
||||
// get affected rows
|
||||
affected := stmt.GetAffectedRows()
|
||||
|
@ -97,6 +98,6 @@ func main() {
|
|||
}
|
||||
err = stmt.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to close stmt, err:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/taosdata/driver-go/v3/af/tmq"
|
||||
|
@ -16,7 +17,7 @@ func main() {
|
|||
// init env
|
||||
conn, err := sql.Open("taosSql", "root:taosdata@tcp(127.0.0.1:6030)/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer func() {
|
||||
conn.Close()
|
||||
|
@ -31,17 +32,17 @@ func main() {
|
|||
"msg.with.table.name": "true",
|
||||
"enable.auto.commit": "true",
|
||||
"auto.commit.interval.ms": "1000",
|
||||
"group.id": "group2",
|
||||
"client.id": "1",
|
||||
"group.id": "group1",
|
||||
"client.id": "client1",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create consumer, err:", err)
|
||||
}
|
||||
// ANCHOR_END: create_consumer
|
||||
// ANCHOR: subscribe
|
||||
err = consumer.Subscribe("topic_meters", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to subscribe, err:", err)
|
||||
}
|
||||
for i := 0; i < 50; i++ {
|
||||
ev := consumer.Poll(100)
|
||||
|
@ -49,23 +50,23 @@ func main() {
|
|||
switch e := ev.(type) {
|
||||
case *tmqcommon.DataMessage:
|
||||
// process your data here
|
||||
fmt.Printf("get message:%v\n", e)
|
||||
fmt.Printf("data:%v\n", e)
|
||||
// ANCHOR: commit_offset
|
||||
// commit offset
|
||||
topicPartition, err := consumer.CommitOffsets([]tmqcommon.TopicPartition{e.TopicPartition})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to commit offset, err:", err)
|
||||
}
|
||||
fmt.Println(topicPartition)
|
||||
// ANCHOR_END: commit_offset
|
||||
case tmqcommon.Error:
|
||||
fmt.Printf("%% Error: %v: %v\n", e.Code(), e)
|
||||
panic(e)
|
||||
log.Fatal("failed to get message, err:", e)
|
||||
}
|
||||
// commit all offsets
|
||||
topicPartition, err := consumer.Commit()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to commit, err:", err)
|
||||
}
|
||||
fmt.Println(topicPartition)
|
||||
|
||||
|
@ -76,7 +77,7 @@ func main() {
|
|||
// get assignment
|
||||
partitions, err := consumer.Assignment()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to get assignment, err:", err)
|
||||
}
|
||||
for i := 0; i < len(partitions); i++ {
|
||||
fmt.Println(partitions[i])
|
||||
|
@ -87,7 +88,27 @@ func main() {
|
|||
Offset: 0,
|
||||
}, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to seek, err:", err)
|
||||
}
|
||||
}
|
||||
fmt.Println("assignment seek to beginning successfully")
|
||||
// poll data again
|
||||
gotData := false
|
||||
for i := 0; i < 50; i++ {
|
||||
if gotData {
|
||||
break
|
||||
}
|
||||
ev := consumer.Poll(100)
|
||||
if ev != nil {
|
||||
switch e := ev.(type) {
|
||||
case *tmqcommon.DataMessage:
|
||||
// process your data here
|
||||
fmt.Printf("second data polled:%v\n", e)
|
||||
gotData = true
|
||||
case tmqcommon.Error:
|
||||
fmt.Printf("%% Error: %v: %v\n", e.Code(), e)
|
||||
log.Fatal("failed to get message, err:", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: seek
|
||||
|
@ -95,12 +116,12 @@ func main() {
|
|||
// unsubscribe
|
||||
err = consumer.Unsubscribe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to unsubscribe, err:", err)
|
||||
}
|
||||
// close consumer
|
||||
err = consumer.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to close consumer, err:", err)
|
||||
}
|
||||
// ANCHOR_END: close
|
||||
<-done
|
||||
|
@ -109,22 +130,22 @@ func main() {
|
|||
func initEnv(conn *sql.DB) {
|
||||
_, err := conn.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
_, err = conn.Exec("CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create stable, err:", err)
|
||||
}
|
||||
_, err = conn.Exec("CREATE TOPIC IF NOT EXISTS topic_meters AS SELECT ts, current, voltage, phase, groupid, location FROM power.meters")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create topic, err:", err)
|
||||
}
|
||||
go func() {
|
||||
for i := 0; i < 10; i++ {
|
||||
time.Sleep(time.Second)
|
||||
_, err = conn.Exec("INSERT INTO power.d1001 USING power.meters TAGS (2, 'California.SanFrancisco') VALUES (NOW , 10.2, 219, 0.32)")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert data, err:", err)
|
||||
}
|
||||
}
|
||||
done <- struct{}{}
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/taosdata/driver-go/v3/common"
|
||||
|
@ -17,7 +18,7 @@ func main() {
|
|||
// init env
|
||||
conn, err := sql.Open("taosWS", "root:taosdata@ws(127.0.0.1:6041)/")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to connect TDengine, err:", err)
|
||||
}
|
||||
defer func() {
|
||||
conn.Close()
|
||||
|
@ -36,17 +37,17 @@ func main() {
|
|||
"msg.with.table.name": "true",
|
||||
"enable.auto.commit": "true",
|
||||
"auto.commit.interval.ms": "1000",
|
||||
"group.id": "group2",
|
||||
"client.id": "1",
|
||||
"group.id": "group1",
|
||||
"client.id": "client1",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create consumer, err:", err)
|
||||
}
|
||||
// ANCHOR_END: create_consumer
|
||||
// ANCHOR: subscribe
|
||||
err = consumer.Subscribe("topic_meters", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to subscribe, err:", err)
|
||||
}
|
||||
for i := 0; i < 50; i++ {
|
||||
ev := consumer.Poll(100)
|
||||
|
@ -54,23 +55,23 @@ func main() {
|
|||
switch e := ev.(type) {
|
||||
case *tmqcommon.DataMessage:
|
||||
// process your data here
|
||||
fmt.Printf("get message:%v\n", e)
|
||||
fmt.Printf("data:%v\n", e)
|
||||
// ANCHOR: commit_offset
|
||||
// commit offset
|
||||
topicPartition, err := consumer.CommitOffsets([]tmqcommon.TopicPartition{e.TopicPartition})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to commit offset, err:", err)
|
||||
}
|
||||
fmt.Println(topicPartition)
|
||||
// ANCHOR_END: commit_offset
|
||||
case tmqcommon.Error:
|
||||
fmt.Printf("%% Error: %v: %v\n", e.Code(), e)
|
||||
panic(e)
|
||||
log.Fatal("failed to get message, err:", e)
|
||||
}
|
||||
// commit all offsets
|
||||
topicPartition, err := consumer.Commit()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to commit, err:", err)
|
||||
}
|
||||
fmt.Println(topicPartition)
|
||||
|
||||
|
@ -81,7 +82,7 @@ func main() {
|
|||
// get assignment
|
||||
partitions, err := consumer.Assignment()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to get assignment, err:", err)
|
||||
}
|
||||
for i := 0; i < len(partitions); i++ {
|
||||
fmt.Println(partitions[i])
|
||||
|
@ -92,7 +93,27 @@ func main() {
|
|||
Offset: 0,
|
||||
}, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to seek, err:", err)
|
||||
}
|
||||
}
|
||||
fmt.Println("assignment seek to beginning successfully")
|
||||
// poll data again
|
||||
gotData := false
|
||||
for i := 0; i < 50; i++ {
|
||||
if gotData {
|
||||
break
|
||||
}
|
||||
ev := consumer.Poll(100)
|
||||
if ev != nil {
|
||||
switch e := ev.(type) {
|
||||
case *tmqcommon.DataMessage:
|
||||
// process your data here
|
||||
fmt.Printf("second data polled:%v\n", e)
|
||||
gotData = true
|
||||
case tmqcommon.Error:
|
||||
fmt.Printf("%% Error: %v: %v\n", e.Code(), e)
|
||||
log.Fatal("failed to get message, err:", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: seek
|
||||
|
@ -100,12 +121,12 @@ func main() {
|
|||
// unsubscribe
|
||||
err = consumer.Unsubscribe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to unsubscribe, err:", err)
|
||||
}
|
||||
// close consumer
|
||||
err = consumer.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to close consumer, err:", err)
|
||||
}
|
||||
// ANCHOR_END: close
|
||||
<-done
|
||||
|
@ -114,22 +135,22 @@ func main() {
|
|||
func initEnv(conn *sql.DB) {
|
||||
_, err := conn.Exec("CREATE DATABASE IF NOT EXISTS power")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create database, err:", err)
|
||||
}
|
||||
_, err = conn.Exec("CREATE STABLE IF NOT EXISTS power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create stable, err:", err)
|
||||
}
|
||||
_, err = conn.Exec("CREATE TOPIC IF NOT EXISTS topic_meters AS SELECT ts, current, voltage, phase, groupid, location FROM power.meters")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to create topic, err:", err)
|
||||
}
|
||||
go func() {
|
||||
for i := 0; i < 10; i++ {
|
||||
time.Sleep(time.Second)
|
||||
_, err = conn.Exec("INSERT INTO power.d1001 USING power.meters TAGS (2, 'California.SanFrancisco') VALUES (NOW , 10.2, 219, 0.32)")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal("failed to insert data, err:", err)
|
||||
}
|
||||
}
|
||||
done <- struct{}{}
|
||||
|
|
|
@ -225,6 +225,9 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
|
|||
<TabItem label="Python" value="python">
|
||||
</TabItem>
|
||||
<TabItem label="Go" value="go">
|
||||
```go
|
||||
{{#include docs/examples/go/schemaless/native/main.go}}
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="Rust" value="rust">
|
||||
除 DSN 不同,其余同 Websocket 代码示例。
|
||||
|
@ -252,9 +255,7 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
|
|||
<TabItem label="Python" value="python">
|
||||
</TabItem>
|
||||
<TabItem label="Go" value="go">
|
||||
```go
|
||||
{{#include docs/examples/go/schemaless/native/main.go}}
|
||||
```
|
||||
不支持
|
||||
</TabItem>
|
||||
<TabItem label="Rust" value="rust">
|
||||
不支持
|
||||
|
|
|
@ -7,32 +7,59 @@ pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
|
|||
cd ../../docs/examples/csharp
|
||||
|
||||
dotnet run --project connect/connect.csproj
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
dotnet run --project sqlInsert/sqlinsert.csproj
|
||||
dotnet run --project query/query.csproj
|
||||
#dotnet run --project subscribe/subscribe.csproj
|
||||
|
||||
#taos -s "drop topic if exists topic_example"
|
||||
taos -s "drop database if exists power"
|
||||
dotnet run --project stmtInsert/stmtinsert.csproj
|
||||
dotnet run --project wsConnect/wsConnect.csproj
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
dotnet run --project influxdbLine/influxdbline.csproj
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
dotnet run --project optsTelnet/optstelnet.csproj
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
dotnet run --project optsJSON/optsJSON.csproj
|
||||
|
||||
taos -s "create database if not exists test"
|
||||
# query
|
||||
taos -s "drop database if exists power"
|
||||
dotnet run --project wsConnect/wsConnect.csproj
|
||||
sleep 1
|
||||
dotnet run --project wsInsert/wsInsert.csproj
|
||||
dotnet run --project wsQuery/wsQuery.csproj
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project sqlInsert/sqlinsert.csproj
|
||||
dotnet run --project query/query.csproj
|
||||
|
||||
|
||||
# stmt
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project wsStmt/wsStmt.csproj
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project stmtInsert/stmtinsert.csproj
|
||||
|
||||
# schemaless
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project wssml/wssml.csproj
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project nativesml/nativesml.csproj
|
||||
|
||||
# subscribe
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
sleep 1
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project wssubscribe/wssubscribe.csproj
|
||||
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
sleep 1
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
dotnet run --project subscribe/subscribe.csproj
|
||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
|||
|
||||
taosd >>/dev/null 2>&1 &
|
||||
taosadapter >>/dev/null 2>&1 &
|
||||
sleep 10
|
||||
sleep 1
|
||||
cd ../../docs/examples/go
|
||||
|
||||
go mod tidy
|
||||
|
@ -12,20 +12,67 @@ go mod tidy
|
|||
go run ./connect/afconn/main.go
|
||||
go run ./connect/cgoexample/main.go
|
||||
go run ./connect/restexample/main.go
|
||||
go run ./connect/connpool/main.go
|
||||
go run ./connect/wsexample/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
go run ./sqlquery/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./queryreqid/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./stmt/native/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./stmt/ws/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./schemaless/native/main.go
|
||||
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./schemaless/ws/main.go
|
||||
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
sleep 1
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./tmq/native/main.go
|
||||
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
sleep 1
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./tmq/ws/main.go
|
||||
|
||||
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
go run ./insert/json/main.go
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
go run ./insert/line/main.go
|
||||
taos -s "drop topic if exists topic_meters"
|
||||
sleep 1
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./insert/sql/main.go
|
||||
taos -s "drop database if exists power"
|
||||
sleep 1
|
||||
go run ./insert/stmt/main.go
|
||||
taos -s "drop database if exists test"
|
||||
sleep 1
|
||||
go run ./insert/telnet/main.go
|
||||
|
||||
go run ./query/sync/main.go
|
||||
|
||||
taos -s "drop topic if exists example_tmq_topic"
|
||||
sleep 1
|
||||
taos -s "drop database if exists example_tmq"
|
||||
sleep 1
|
||||
go run ./sub/main.go
|
||||
|
|
Loading…
Reference in New Issue