Skip to content

Commit 2ca0ec4

Browse files
authored
docs: Examples (#8)
* docs: Added basic and auth-tls examples. * chore: Added CI. * chore: Added CODEOWNERS. * chore: Hiding Visual Studio Backup directory in .gitignore. * test: Fixed tests on Windows. * doc: Added a link to the QuestDB .NET library on NuGet. * chore: Fixing broken examples.manifest.yaml auth substitution string.
1 parent 1b1e2ab commit 2ca0ec4

12 files changed

+195
-6
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vs/
2+
Backup/
3+
src/tcp-client-test/bin/
4+
src/tcp-client-test/obj/
5+
src/example-auth-tls/bin/
6+
src/example-auth-tls/obj/
7+
src/example-basic/bin/
8+
src/example-basic/obj/
9+
src/net-questdb-client/bin/
10+
src/net-questdb-client/obj/
11+
UpgradeLog.htm

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @questdb/engineering

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@ await ls.SendAsync();
7777
| `TrimExcessBuffers()` | Trims empty buffers used to grow IO Buffer. Only useful when `bufferOverflowHandling` set to `Extend` |
7878
| int `WriteTimeout` | Value, in milliseconds, that determines how long the underlying stream will attempt to write before timing out |
7979
| `IsConnected` | Indicates if the connection to QuestDB open |
80+
81+
### Examples
82+
83+
* [Basic](src/example-basic/Program.cs)
84+
* [Auth + TLS](src/example-auth-tls/Program.cs)
85+
86+
87+
### Using this library in your code
88+
89+
Use NuGet to add a depency on this library.
90+
91+
See: [https://www.nuget.org/packages/net-questdb-client/](https://www.nuget.org/packages/net-questdb-client/)

ci/run_tests_pipeline.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
trigger: none
2+
3+
stages:
4+
- stage: BuildAndTest
5+
displayName: "Building and testing"
6+
jobs:
7+
- job: RunOn
8+
displayName: "on"
9+
strategy:
10+
matrix:
11+
linux:
12+
imageName: "ubuntu-latest"
13+
poolName: "Azure Pipelines"
14+
windows-msvc-2022:
15+
imageName: "windows-2022"
16+
poolName: "Azure Pipelines"
17+
windows-msvc-2019:
18+
imageName: "windows-2019"
19+
poolName: "Azure Pipelines"
20+
pool:
21+
name: $(poolName)
22+
vmImage: $(imageName)
23+
timeoutInMinutes: 60
24+
steps:
25+
- checkout: self
26+
fetchDepth: 1
27+
lfs: false
28+
submodules: true
29+
- script: dotnet build
30+
displayName: Build
31+
- script: dotnet test
32+
displayName: Test

examples.manifest.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- name: ilp
2+
lang: csharp
3+
path: src/example-basic/Program.cs
4+
header: |-
5+
[.NET client library](https://github.com/questdb/net-questdb-client)
6+
7+
- name: ilp-auth-tls
8+
lang: csharp
9+
path: src/example-auth-tls/Program.cs
10+
header: |-
11+
[.NET client library](https://github.com/questdb/net-questdb-client)
12+
auth:
13+
kid: admin
14+
d: NgdiOWDoQNUP18WOnb1xkkEG5TzPYMda5SiUOvT1K0U=
15+
addr:
16+
host: localhost
17+
port: 9009

src/net-questdb-client.sln.sln renamed to net-questdb-client.sln

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "net-questdb-client", "net-questdb-client\net-questdb-client.csproj", "{456B1860-0102-48D7-861A-5F9963F3887B}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "net-questdb-client", "src\net-questdb-client\net-questdb-client.csproj", "{456B1860-0102-48D7-861A-5F9963F3887B}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tcp-client-test", "tcp-client-test\tcp-client-test.csproj", "{22F903D9-4367-46A2-A25A-F4A6BF9105C6}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tcp-client-test", "src\tcp-client-test\tcp-client-test.csproj", "{22F903D9-4367-46A2-A25A-F4A6BF9105C6}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-basic", "src\example-basic\example-basic.csproj", "{121EAA4D-3A73-468C-8CAB-A2A4BEF848CF}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-auth-tls", "src\example-auth-tls\example-auth-tls.csproj", "{FBB8181C-6BAB-46C2-A47A-D3566A3997FE}"
913
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -24,5 +28,13 @@ Global
2428
{22F903D9-4367-46A2-A25A-F4A6BF9105C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
2529
{22F903D9-4367-46A2-A25A-F4A6BF9105C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
2630
{22F903D9-4367-46A2-A25A-F4A6BF9105C6}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{121EAA4D-3A73-468C-8CAB-A2A4BEF848CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{121EAA4D-3A73-468C-8CAB-A2A4BEF848CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{121EAA4D-3A73-468C-8CAB-A2A4BEF848CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{121EAA4D-3A73-468C-8CAB-A2A4BEF848CF}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{FBB8181C-6BAB-46C2-A47A-D3566A3997FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{FBB8181C-6BAB-46C2-A47A-D3566A3997FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{FBB8181C-6BAB-46C2-A47A-D3566A3997FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{FBB8181C-6BAB-46C2-A47A-D3566A3997FE}.Release|Any CPU.Build.0 = Release|Any CPU
2739
EndGlobalSection
2840
EndGlobal

src/example-auth-tls/Program.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using QuestDB;
2+
using System;
3+
using System.Threading.Tasks;
4+
5+
namespace QuestDBDemo
6+
{
7+
class Program
8+
{
9+
static async Task Main(string[] args)
10+
{
11+
using var sender = await LineTcpSender.ConnectAsync(
12+
"localhost",
13+
9009,
14+
tlsMode: TlsMode.Enable);
15+
// See: https://questdb.io/docs/reference/api/ilp/authenticate
16+
await sender.AuthenticateAsync(
17+
"admin", // kid
18+
"NgdiOWDoQNUP18WOnb1xkkEG5TzPYMda5SiUOvT1K0U="); // d
19+
sender.Table("trades")
20+
.Symbol("pair", "USDGBP")
21+
.Symbol("type", "buy")
22+
.Column("traded_price", 0.83)
23+
.Column("limit_price", 0.84)
24+
.Column("qty", 100)
25+
.Column("traded_ts", new DateTime(
26+
2022, 8, 6, 7, 35, 23, 189, DateTimeKind.Utc))
27+
.At(DateTime.UtcNow);
28+
sender.Table("trades")
29+
.Symbol("pair", "GBPJPY")
30+
.Column("traded_price", 135.97)
31+
.Column("qty", 400)
32+
.AtNow();
33+
await sender.SendAsync();
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netstandard2.1</TargetFramework>
6+
<RootNamespace>QuestDBDemo</RootNamespace>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>10</LangVersion>
9+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
10+
<Title>QuestDB client - Example with Authentication and TLS</Title>
11+
<Description>Authentication and TLS example using the QuestDB ILP protocol client</Description>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\net-questdb-client\net-questdb-client.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

src/example-basic/Program.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using QuestDB;
2+
using System;
3+
using System.Threading.Tasks;
4+
5+
namespace QuestDBDemo
6+
{
7+
class Program
8+
{
9+
static async Task Main(string[] args)
10+
{
11+
using var sender = await LineTcpSender.ConnectAsync(
12+
"localhost",
13+
9009,
14+
tlsMode: TlsMode.Disable);
15+
sender.Table("trades")
16+
.Symbol("pair", "USDGBP")
17+
.Symbol("type", "buy")
18+
.Column("traded_price", 0.83)
19+
.Column("limit_price", 0.84)
20+
.Column("qty", 100)
21+
.Column("traded_ts", new DateTime(
22+
2022, 8, 6, 7, 35, 23, 189, DateTimeKind.Utc))
23+
.At(DateTime.UtcNow);
24+
sender.Table("trades")
25+
.Symbol("pair", "GBPJPY")
26+
.Column("traded_price", 135.97)
27+
.Column("qty", 400)
28+
.AtNow();
29+
await sender.SendAsync();
30+
}
31+
}
32+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netstandard2.1</TargetFramework>
6+
<RootNamespace>QuestDBDemo</RootNamespace>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>10</LangVersion>
9+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
10+
<Title>QuestDB client - Basic Example</Title>
11+
<Description>Basic example using the QuestDB ILP protocol client</Description>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\net-questdb-client\net-questdb-client.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

src/net-questdb-client/net-questdb-client.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<Title>QuestDB client</Title>
1010
<Description>Simple QuestDB ILP protocol client</Description>
11-
<Copyright>QuesetDB</Copyright>
11+
<Copyright>QuestDB</Copyright>
1212
<PackageProjectUrl>https://questdb.io</PackageProjectUrl>
1313
<PackageLicenseUrl>Apache 2.0</PackageLicenseUrl>
1414
<RepositoryUrl>https://github.com/questdb/net-questdb-client</RepositoryUrl>

src/tcp-client-test/LineTcpSenderTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public async Task AuthFailBadKey()
132132
}
133133
catch (IOException ex)
134134
{
135-
Assert.That(ex.Message, Is.EqualTo("Unable to write data to the transport connection: Broken pipe."));
135+
StringAssert.StartsWith("Unable to write data to the transport connection: ", ex.Message, "Bad exception message");
136136
}
137137
}
138138

@@ -614,7 +614,7 @@ public async Task CannotConnect()
614614
}
615615
catch (SocketException ex)
616616
{
617-
Assert.That(ex.Message, Is.EqualTo("Connection refused"));
617+
StringAssert.IsMatch(".*(Connection refused|No connection could be made).*", ex.Message);
618618
}
619619
}
620620

0 commit comments

Comments
 (0)