@@ -9,7 +9,7 @@ Golang client for QuestDB's [Influx Line Protocol](https://questdb.io/docs/refer
9
9
The library requires Go 1.19 or newer.
10
10
11
11
Features:
12
- * Context-aware API.
12
+ * [ Context] ( https://www.digitalocean.com/community/tutorials/how-to-use-contexts-in-go ) -aware API.
13
13
* Optimized for batch writes.
14
14
* Supports TLS encryption and ILP authentication.
15
15
* Automatic write retries and connection reuse for ILP over HTTP.
@@ -43,23 +43,40 @@ func main() {
43
43
}
44
44
// Make sure to close the sender on exit to release resources.
45
45
defer sender.Close (ctx)
46
+
46
47
// Send a few ILP messages.
48
+ tradedTs , err := time.Parse (time.RFC3339 , " 2022-08-06T15:04:05.123456Z" )
49
+ if err != nil {
50
+ log.Fatal (err)
51
+ }
47
52
err = sender.
48
- Table (" trades" ).
49
- Symbol (" name" , " test_ilp1" ).
50
- Float64Column (" value" , 12.4 ).
51
- AtNow (ctx)
53
+ Table (" trades_go" ).
54
+ Symbol (" pair" , " USDGBP" ).
55
+ Symbol (" type" , " buy" ).
56
+ Float64Column (" traded_price" , 0.83 ).
57
+ Float64Column (" limit_price" , 0.84 ).
58
+ Int64Column (" qty" , 100 ).
59
+ At (ctx, tradedTs)
60
+ if err != nil {
61
+ log.Fatal (err)
62
+ }
63
+
64
+ tradedTs, err = time.Parse (time.RFC3339 , " 2022-08-06T15:04:06.987654Z" )
52
65
if err != nil {
53
66
log.Fatal (err)
54
67
}
55
68
err = sender.
56
- Table (" trades" ).
57
- Symbol (" name" , " test_ilp2" ).
58
- Float64Column (" value" , 11.4 ).
59
- At (ctx, time.Now ().UnixNano ())
69
+ Table (" trades_go" ).
70
+ Symbol (" pair" , " GBPJPY" ).
71
+ Symbol (" type" , " sell" ).
72
+ Float64Column (" traded_price" , 135.97 ).
73
+ Float64Column (" limit_price" , 0.84 ).
74
+ Int64Column (" qty" , 400 ).
75
+ At (ctx, tradedTs)
60
76
if err != nil {
61
77
log.Fatal (err)
62
78
}
79
+
63
80
// Make sure that the messages are sent over the network.
64
81
err = sender.Flush (ctx)
65
82
if err != nil {
@@ -80,15 +97,15 @@ To connect via TCP, set the configuration string to:
80
97
** Warning: Experimental feature designed for use with HTTP senders ONLY**
81
98
82
99
Version 3 of the client introduces a ` LineSenderPool ` , which provides a mechanism
83
- to cache previously-used ` LineSender ` s in memory so they can be reused without
84
- having to allocate and instantiate new senders.
100
+ to pool previously-used ` LineSender ` s so they can be reused without having
101
+ to allocate and instantiate new senders.
85
102
86
- A LineSenderPool is thread-safe and can be used to concurrently Acquire and Release senders
103
+ A LineSenderPool is thread-safe and can be used to concurrently obtain senders
87
104
across multiple goroutines.
88
105
89
106
Since ` LineSender ` s must be used in a single-threaded context, a typical pattern is to Acquire
90
107
a sender from a ` LineSenderPool ` at the beginning of a goroutine and use a deferred
91
- execution block to Release the sender at the end of the goroutine.
108
+ execution block to Close the sender at the end of the goroutine.
92
109
93
110
Here is an example of the ` LineSenderPool ` Acquire, Release, and Close semantics:
94
111
@@ -112,7 +129,7 @@ func main() {
112
129
}
113
130
}()
114
131
115
- sender , err := pool.Acquire (ctx)
132
+ sender , err := pool.Sender (ctx)
116
133
if err != nil {
117
134
panic (err)
118
135
}
@@ -122,7 +139,8 @@ func main() {
122
139
Float64Column (" price" , 123.45 ).
123
140
AtNow (ctx)
124
141
125
- if err := pool.Release (ctx, sender); err != nil {
142
+ // Close call returns the sender back to the pool
143
+ if err := sender.Close (ctx); err != nil {
126
144
panic (err)
127
145
}
128
146
}
0 commit comments