From aa97c918b33ac4b6e3caaa850dff761c677167b6 Mon Sep 17 00:00:00 2001 From: Luke Bond Date: Fri, 10 Jun 2022 10:13:17 +0100 Subject: [PATCH] docs: fix README for influxdb_iox_client (#4825) Closes #4816 --- influxdb_iox_client/README.md | 67 ++++++++----------------- influxdb_iox_client/src/client/write.rs | 2 +- 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/influxdb_iox_client/README.md b/influxdb_iox_client/README.md index 7ce3325b9a..6624241fe3 100644 --- a/influxdb_iox_client/README.md +++ b/influxdb_iox_client/README.md @@ -2,61 +2,36 @@ This is the official Rust client library for connecting to InfluxDB IOx. -## Using the HTTP API +Currently only gRPC is supported. -If you only want to use the HTTP API, create an `influxdb_iox_client::Client`. Here is an example of -creating an instance that connects to an IOx server running at `http://127.0.0.1:8080` and creating -a database named `telemetry`: +## Using the gRPC Write Client + +To write to IOx, create a connection and a write client, and then send line +protocol. Here is an example of creating an instance that connects to an IOx +server running at `http://127.0.0.1:8081` (the default bind address for the +gRPC endpoint of IOx when running in all-in-one mode) and sending a line of +line protocol: ```rust #[tokio::main] fn main() { - use data_types::database_rules::DatabaseRules; - use influxdb_iox_client::ClientBuilder; + use influxdb_iox_client::{ + write::Client, + connection::Builder, + }; - let client = ClientBuilder::default() - .build("http://127.0.0.1:8080") - .expect("client should be valid"); - - client - .create_database("telemetry", &DatabaseRules::default()) + let mut connection = Builder::default() + .build("http://127.0.0.1:8081") .await - .expect("failed to create database"); -} -``` + .unwrap(); -## Using the Arrow Flight API + let mut client = Client::new(connection); -IOx supports an [Arrow Flight gRPC API](https://arrow.apache.org/docs/format/Flight.html). To use -it, enable the `flight` feature, which is off by default: - -```toml -[dependencies] -influxdb_iox_client = { version = "[..]", features = ["flight"] } -``` - -Then you can create an `influxdb_iox_client::FlightClient` by using the `FlightClientBuilder`. Here -is an example of creating an instance that connects to an IOx server with its gRPC services -available at `http://localhost:8082` and using it to perform a query: - -```rust -#[tokio::main] -fn main() { - use data_types::database_rules::DatabaseRules; - use influxdb_iox_client::FlightClientBuilder; - - let client = FlightClientBuilder::default() - .build("http://127.0.0.1:8082") - .expect("client should be valid"); - - let mut query_results = client - .perform_query(scenario.database_name(), sql_query) - .await; - - let mut batches = vec![]; - - while let Some(data) = query_results.next().await { - batches.push(data); + // write a line of line procol data + client + .write_lp("bananas", "cpu,region=west user=23.2 100",0) + .await + .expect("failed to write to IOx"); } } ``` diff --git a/influxdb_iox_client/src/client/write.rs b/influxdb_iox_client/src/client/write.rs index 3d27a0c47e..146b91f953 100644 --- a/influxdb_iox_client/src/client/write.rs +++ b/influxdb_iox_client/src/client/write.rs @@ -29,7 +29,7 @@ use crate::error::Error; /// client /// .write_lp("bananas", "cpu,region=west user=23.2 100",0) /// .await -/// .expect("failed to create database"); +/// .expect("failed to write to IOx"); /// # } /// ``` #[derive(Debug, Clone)]