Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (62 loc) · 3.02 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (62 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2026 QuestDB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
using System;
using QuestDB;
using QuestDB.Senders;
// Connect via the WebSocket / QWP transport. The wire format is a columnar binary
// protocol — much smaller and faster than the text ILP that http:: and tcp:: use.
//
// Connect-string knobs that matter for ws::
// addr host:port (default port 9000, shared with HTTP)
// auto_flush_rows rows before an automatic flush is triggered (default 1000 for ws)
// auto_flush_interval milliseconds before an automatic flush (default 100 for ws)
// close_flush_timeout_millis drain timeout (default 60000) for a standalone Send() and the no-arg
// Flush(). NOTE: Dispose does NOT drain — a standalone Send() delivers on its own.
// request_durable_ack on/off — opt in to per-table durable seqTxn watermarks
// username/password Basic auth, or
// token Bearer auth
await using var sender = Sender.New("ws::addr=localhost:9000;request_durable_ack=on;");
await sender.Table("trades")
.Symbol("symbol", "ETH-USD")
.Symbol("side", "sell")
.Column("price", 2615.54)
.Column("amount", 0.00044)
.AtAsync(DateTime.UtcNow);
await sender.Table("trades")
.Symbol("symbol", "BTC-USD")
.Symbol("side", "buy")
.Column("price", 39269.98)
.Column("amount", 0.001)
.AtAsync(DateTime.UtcNow);
// A standalone ws:: Send drains — it flushes the buffered rows AND blocks until the server acknowledges
// them — so "Send before dispose" reliably delivers even though Dispose does not wait. (Send throws on a
// drain timeout, bounded by close_flush_timeout_millis; use Flush(timeout) for a bounded, bool-returning drain.)
await sender.SendAsync();
// When `request_durable_ack=on` is set, the WebSocket sender exposes per-table seqTxn watermarks
// via the IQwpWebSocketSender interface.
if (sender is IQwpWebSocketSender ws)
{
Console.WriteLine($"trades committed seqTxn: {ws.GetHighestAckedSeqTxn("trades")}");
Console.WriteLine($"trades durable seqTxn: {ws.GetHighestDurableSeqTxn("trades")}");
}