pub struct Sender { /* private fields */ }
Expand description
Connects to a QuestDB instance and inserts data via the ILP protocol.
- To construct an instance, use
Sender::from_conf
or theSenderBuilder
. - To prepare messages, use
Buffer
objects. - To send messages, call the
flush
method.
Implementations§
source§impl Sender
impl Sender
sourcepub fn from_conf<T: AsRef<str>>(conf: T) -> Result<Self>
pub fn from_conf<T: AsRef<str>>(conf: T) -> Result<Self>
Create a new Sender
instance from configuration string.
The format of the string is: "http::addr=host:port;key=value;...;"
.
Alongside "http"
you can also specify "https"
, "tcp"
, and "tcps"
.
HTTP is recommended in most cases as is provides better error feedback allows controlling transactions. TCP can sometimes be faster in higher-latency networks, but misses out on a number of features.
The accepted set of keys and values is the same as for the opt’s API.
E.g. "https::addr=host:port;username=alice;password=secret;tls_ca=os_roots;"
.
For full list of keys and values, see the SenderBuilder
documentation:
The builder API and the configuration string API are equivalent.
If you prefer, you can also load the configuration from an environment variable.
See Sender::from_env
.
sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new Sender
from the QDB_CLIENT_CONF
environment variable.
The format is the same as that taken by Sender::from_conf
.
sourcepub fn flush_and_keep_with_flags(
&mut self,
buf: &Buffer,
transactional: bool
) -> Result<()>
pub fn flush_and_keep_with_flags( &mut self, buf: &Buffer, transactional: bool ) -> Result<()>
Variant of .flush()
that does not clear the buffer and allows for
transactional flushes.
A transactional flush is simply a flush that ensures that all rows in the ILP buffer refer to the same table, thus allowing the server to treat the flush request as a single transaction.
This is because QuestDB does not support transactions spanning multiple tables.
Note that transactional flushes are only supported for ILP over HTTP.
sourcepub fn flush_and_keep(&mut self, buf: &Buffer) -> Result<()>
pub fn flush_and_keep(&mut self, buf: &Buffer) -> Result<()>
Variant of .flush()
that does not clear the buffer.
sourcepub fn flush(&mut self, buf: &mut Buffer) -> Result<()>
pub fn flush(&mut self, buf: &mut Buffer) -> Result<()>
Send buffer to the QuestDB server, clearing the buffer.
If sending over HTTP, flushing will send an HTTP request and wait for the response. If the server responds with an error, this function will return a descriptive error. In case of network errors, this function will retry.
If sending over TCP, this will block until the buffer is flushed to the network socket. Note that this does not guarantee that the buffer will be sent to the server or that the server has received it. In case of errors the server will disconnect: consult the server logs.
Prefer HTTP in most cases, but use TCP if you need to continuously data to the server at a high rate.
To improve HTTP performance, send larger buffers (with more rows), and consider parallelizing writes using multiple senders from multiple threads.
sourcepub fn must_close(&self) -> bool
pub fn must_close(&self) -> bool
The sender is no longer usable and must be dropped.
This is caused if there was an earlier failure.
This method is specific to ILP/TCP and is not relevant for ILP/HTTP.