- To begin with, we suggest first building the library to ensure you have all the tooling and build dependencies set up just right by following the build instructions
- Then read the guide for including this library as a dependency from your project.
- Basic example in C++.
- With authentication.
- With authentication and TLS.
- Custom certificate authority file.
#include <questdb/ilp/line_sender.hpp>
...
// Automatically connects on object construction.
questdb::ilp::line_sender sender{
"localhost", // QuestDB hostname
9009}; // QuestDB port
For more advanced use cases, such as those requiring authentication or
full-connection encryption via TLS, first, create an opts
object then call its
methods to populate its options and then pass the opts
object to the
line_sender
constructor.
The line_sender
object is responsible for connecting to the network and
sending data.
Use the line_sender_buffer
type to construct messages (aka rows, aka records,
aka lines).
To avoid malformed messages, the line_sender_buffer
object's methods
must be called in a specific order.
For each row, you need to specify a table name and at least one symbol or column. Symbols must be specified before columns.
You can accumulate multiple lines (rows) with a given buffer and a buffer is
re-usable, but a buffer may only be flushed via the sender after a call to
buffer.at(..)
or buffer.at_now()
.
questdb::ilp::line_sender_buffer buffer;
buffer
.table("cpp_cars")
.symbol("id", "d6e5fe92-d19f-482a-a97a-c105f547f721")
.column("x", 30.5)
.at_now();
// To insert more records, call `buffer.table(..)...` again.
sender.flush(buffer);
Diagram of valid call order of the buffer API.
Note that most methods in C++ may throw questdb::ilp::line_sender_error
exceptions. The C++ line_sender_error
type inherits from std::runtime_error
and you can obtain an error message description by calling .what()
and an
error code calling .code()
.