|
29 | 29 | //! (ILP) over TCP.
|
30 | 30 | //!
|
31 | 31 | //! To get started:
|
32 |
| -//! * Connect to QuestDB by creating a [`Sender`] object. |
| 32 | +//! * Connect to QuestDB by creating a [`Sender`] object, usually via [`Sender::from_conf`]. |
33 | 33 | //! * Populate a [`Buffer`] with one or more rows of data.
|
34 | 34 | //! * Send the buffer via the Sender's [`flush`](Sender::flush) method.
|
35 | 35 | //!
|
36 |
| -//! ```no_run |
| 36 | +//! ```rust no_run |
37 | 37 | //! use questdb::{
|
38 | 38 | //! Result,
|
39 | 39 | //! ingress::{
|
40 | 40 | //! Sender,
|
41 | 41 | //! Buffer,
|
42 |
| -//! SenderBuilder, |
43 | 42 | //! TimestampNanos}};
|
44 |
| -//! |
| 43 | +//! |
45 | 44 | //! fn main() -> Result<()> {
|
46 |
| -//! let mut sender = SenderBuilder::new_tcp("localhost", 9009).build()?; |
| 45 | +//! let mut sender = Sender::from_conf("http::addr=localhost:9000;")?; |
47 | 46 | //! let mut buffer = Buffer::new();
|
48 | 47 | //! buffer
|
49 | 48 | //! .table("sensors")?
|
@@ -1325,7 +1324,7 @@ impl Default for Buffer {
|
1325 | 1324 |
|
1326 | 1325 | /// Connects to a QuestDB instance and inserts data via the ILP protocol.
|
1327 | 1326 | ///
|
1328 |
| -/// * To construct an instance, use the [`SenderBuilder`]. |
| 1327 | +/// * To construct an instance, use [`Sender::from_conf`] or the [`SenderBuilder`]. |
1329 | 1328 | /// * To prepare messages, use [`Buffer`] objects.
|
1330 | 1329 | /// * To send messages, call the [`flush`](Sender::flush) method.
|
1331 | 1330 | pub struct Sender {
|
@@ -1724,10 +1723,24 @@ pub struct SenderBuilder {
|
1724 | 1723 |
|
1725 | 1724 | impl SenderBuilder {
|
1726 | 1725 | /// Create a new `SenderBuilder` instance from configuration string.
|
1727 |
| - /// The format of the string is: "tcp::addr=host:port;ket=value;...;" |
1728 |
| - /// Alongside "tcp" you can also specify "tcps", "http", and "https". |
| 1726 | + /// |
| 1727 | + /// The format of the string is: `"http::addr=host:port;ket=value;...;"`. |
| 1728 | + /// |
| 1729 | + /// Alongside `"http"` you can also specify `"https"`, `"tcp"`, and `"tcps"`. |
| 1730 | + /// |
| 1731 | + /// HTTP is recommended in most cases as is provides better error feedback |
| 1732 | + /// allows controlling transactions. TCP can sometimes be faster in higher-latency |
| 1733 | + /// networks, but misses out on a number of features. |
| 1734 | + /// |
1729 | 1735 | /// The accepted set of keys and values is the same as for the `SenderBuilder`'s API.
|
1730 |
| - /// E.g. "tcp::addr=host:port;user=alice;password=secret;tls_ca=os_roots;" |
| 1736 | + /// |
| 1737 | + /// E.g. `"http::addr=host:port;user=alice;password=secret;tls_ca=os_roots;"`. |
| 1738 | + /// |
| 1739 | + /// If you prefer, you can also load the configuration from an environment variable. |
| 1740 | + /// See [`SenderBuilder::from_env`]. |
| 1741 | + /// |
| 1742 | + /// Once a `SenderBuilder` is created from a string (or from the environment variable) |
| 1743 | + /// it can be further customized before calling [`SenderBuilder::build`]. |
1731 | 1744 | pub fn from_conf<T: AsRef<str>>(conf: T) -> Result<Self> {
|
1732 | 1745 | let conf = conf.as_ref();
|
1733 | 1746 | let conf = questdb_confstr::parse_conf_str(conf)
|
@@ -1885,6 +1898,8 @@ impl SenderBuilder {
|
1885 | 1898 |
|
1886 | 1899 | /// Create a new `SenderBuilder` instance from configuration string read from the
|
1887 | 1900 | /// `QDB_CLIENT_CONF` environment variable.
|
| 1901 | + /// |
| 1902 | + /// The format of the string is the same as for [`SenderBuilder::from_conf`]. |
1888 | 1903 | pub fn from_env() -> Result<Self> {
|
1889 | 1904 | let conf = std::env::var("QDB_CLIENT_CONF").map_err(|_| {
|
1890 | 1905 | error::fmt!(ConfigError, "Environment variable QDB_CLIENT_CONF not set.")
|
@@ -2607,12 +2622,31 @@ impl F64Serializer {
|
2607 | 2622 | }
|
2608 | 2623 |
|
2609 | 2624 | impl Sender {
|
2610 |
| - /// Create a new `Sender` from configuration parameters. |
| 2625 | + /// Create a new `Sender` instance from configuration string. |
| 2626 | + /// |
| 2627 | + /// The format of the string is: `"http::addr=host:port;key=value;...;"`. |
| 2628 | + /// |
| 2629 | + /// Alongside `"http"` you can also specify `"https"`, `"tcp"`, and `"tcps"`. |
| 2630 | + /// |
| 2631 | + /// HTTP is recommended in most cases as is provides better error feedback |
| 2632 | + /// allows controlling transactions. TCP can sometimes be faster in higher-latency |
| 2633 | + /// networks, but misses out on a number of features. |
| 2634 | + /// |
| 2635 | + /// The accepted set of keys and values is the same as for the opt's API. |
| 2636 | + /// |
| 2637 | + /// E.g. `"http::addr=host:port;user=alice;password=secret;tls_ca=os_roots;"`. |
| 2638 | + /// |
| 2639 | + /// For full list of keys and values, see the [`SenderBuilder`] documentation: |
| 2640 | + /// The builder API and the configuration string API are equivalent. |
| 2641 | + /// |
| 2642 | + /// If you prefer, you can also load the configuration from an environment variable. |
| 2643 | + /// See [`Sender::from_env`]. |
2611 | 2644 | pub fn from_conf<T: AsRef<str>>(conf: T) -> Result<Self> {
|
2612 | 2645 | SenderBuilder::from_conf(conf)?.build()
|
2613 | 2646 | }
|
2614 | 2647 |
|
2615 | 2648 | /// Create a new `Sender` from the `QDB_CLIENT_CONF` environment variable.
|
| 2649 | + /// The format is the same as that taken by [`Sender::from_conf`]. |
2616 | 2650 | pub fn from_env() -> Result<Self> {
|
2617 | 2651 | SenderBuilder::from_env()?.build()
|
2618 | 2652 | }
|
@@ -2706,6 +2740,8 @@ impl Sender {
|
2706 | 2740 | ///
|
2707 | 2741 | /// This is because QuestDB does not support transactions spanning multiple
|
2708 | 2742 | /// tables.
|
| 2743 | + /// |
| 2744 | + /// Note that transactional flushes are only supported for ILP over HTTP. |
2709 | 2745 | #[cfg(feature = "ilp-over-http")]
|
2710 | 2746 | pub fn flush_and_keep_with_flags(&mut self, buf: &Buffer, transactional: bool) -> Result<()> {
|
2711 | 2747 | self.flush_impl(buf, transactional)
|
|
0 commit comments