pub struct ClientConfig { /* private fields */ }
Expand description
Client configuration.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new(token: impl Into<String>) -> Self
pub fn new(token: impl Into<String>) -> Self
Initialize a default client configuration with the specified authentication token.
Examples found in repository?
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let token = std::env::var("S2_ACCESS_TOKEN")?;
9 let config = ClientConfig::new(token);
10 let basin: BasinName = "my-favorite-basin".parse()?;
11 let basin_client = BasinClient::new(config, basin);
12
13 let stream = "my-favorite-stream";
14
15 let delete_stream_request = DeleteStreamRequest::new(stream);
16
17 basin_client.delete_stream(delete_stream_request).await?;
18
19 Ok(())
20}
More examples
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let token = std::env::var("S2_ACCESS_TOKEN")?;
9 let config = ClientConfig::new(token);
10 let client = Client::new(config);
11
12 let basin: BasinName = "my-favorite-basin".parse()?;
13
14 let delete_basin_request = DeleteBasinRequest::new(basin)
15 // Don't error if the basin doesn't exist.
16 .with_if_exists(true);
17
18 client.delete_basin(delete_basin_request).await?;
19
20 Ok(())
21}
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let token = std::env::var("S2_ACCESS_TOKEN")?;
9 let config = ClientConfig::new(token);
10 let basin: BasinName = "my-favorite-basin".parse()?;
11 let basin_client = BasinClient::new(config, basin);
12
13 let prefix = "my-";
14 let list_streams_request = ListStreamsRequest::new().with_prefix(prefix);
15
16 let list_streams_response = basin_client.list_streams(list_streams_request).await?;
17
18 println!("{list_streams_response:#?}");
19
20 Ok(())
21}
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let token = std::env::var("S2_ACCESS_TOKEN")?;
9 let config = ClientConfig::new(token);
10 let basin: BasinName = "my-favorite-basin".parse()?;
11 let stream = "my-favorite-stream";
12 let stream_client = StreamClient::new(config, basin, stream);
13
14 let read_limit = ReadLimit::new().with_count(1);
15 let read_request = ReadRequest::new(ReadStart::TailOffset(1)).with_limit(read_limit);
16 let latest_record = stream_client.read(read_request).await?;
17
18 println!("{latest_record:#?}");
19
20 Ok(())
21}
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let token = std::env::var("S2_ACCESS_TOKEN")?;
9 let config = ClientConfig::new(token);
10 let client = Client::new(config);
11
12 let basin: BasinName = "my-favorite-basin".parse()?;
13 let basin_client = client.basin_client(basin);
14
15 let stream = "my-favorite-stream";
16
17 let stream_config = StreamConfig::new().with_storage_class(StorageClass::Express);
18
19 let create_stream_request = CreateStreamRequest::new(stream).with_config(stream_config);
20
21 let created_stream = basin_client.create_stream(create_stream_request).await?;
22 println!("{created_stream:#?}");
23
24 let stream_config = basin_client.get_stream_config(stream).await?;
25 println!("{stream_config:#?}");
26
27 Ok(())
28}
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10 let token = std::env::var("S2_ACCESS_TOKEN")?;
11 let config = ClientConfig::new(token);
12 let basin: BasinName = "my-favorite-basin".parse()?;
13 let stream = "my-favorite-stream";
14 let stream_client = StreamClient::new(config, basin, stream);
15
16 let start_seq_num = 0;
17 let read_session_request = ReadSessionRequest::new(ReadStart::SeqNum(start_seq_num));
18 let mut read_stream = stream_client.read_session(read_session_request).await?;
19
20 loop {
21 select! {
22 next_batch = read_stream.next() => {
23 let Some(next_batch) = next_batch else { break };
24 let next_batch = next_batch?;
25 println!("{next_batch:?}");
26 }
27 _ = tokio::signal::ctrl_c() => break,
28 }
29 }
30
31 Ok(())
32}
Sourcepub fn with_endpoints(self, host_endpoints: impl Into<S2Endpoints>) -> Self
pub fn with_endpoints(self, host_endpoints: impl Into<S2Endpoints>) -> Self
S2 endpoints to connect to.
Sourcepub fn with_connection_timeout(
self,
connection_timeout: impl Into<Duration>,
) -> Self
pub fn with_connection_timeout( self, connection_timeout: impl Into<Duration>, ) -> Self
Timeout for connecting and transparently reconnecting. Defaults to 3s.
Sourcepub fn with_request_timeout(self, request_timeout: impl Into<Duration>) -> Self
pub fn with_request_timeout(self, request_timeout: impl Into<Duration>) -> Self
Timeout for a particular request. Defaults to 5s.
Sourcepub fn with_user_agent(self, user_agent: HeaderValue) -> Self
pub fn with_user_agent(self, user_agent: HeaderValue) -> Self
User agent. Defaults to s2-sdk-rust
. Feel free to say hi.
Sourcepub fn with_append_retry_policy(
self,
append_retry_policy: impl Into<AppendRetryPolicy>,
) -> Self
pub fn with_append_retry_policy( self, append_retry_policy: impl Into<AppendRetryPolicy>, ) -> Self
Retry policy for appends.
Only relevant if max_attempts > 1
.
Defaults to retries of all failures, meaning duplicates on a stream are possible.
Sourcepub fn with_max_append_inflight_bytes(
self,
max_append_inflight_bytes: u64,
) -> Self
pub fn with_max_append_inflight_bytes( self, max_append_inflight_bytes: u64, ) -> Self
Maximum total size of currently inflight (pending acknowledgment) append
batches, per append session, as measured by MeteredSize
formula.
Must be at least 1 MiB. Defaults to 100 MiB.
Sourcepub fn with_uri_scheme(self, uri_scheme: impl Into<Scheme>) -> Self
pub fn with_uri_scheme(self, uri_scheme: impl Into<Scheme>) -> Self
URI scheme to use when connecting with a custom connector. Defaults to https
.
Sourcepub fn with_retry_backoff_duration(
self,
retry_backoff_duration: impl Into<Duration>,
) -> Self
pub fn with_retry_backoff_duration( self, retry_backoff_duration: impl Into<Duration>, ) -> Self
Backoff duration when retrying. Defaults to 100ms. A jitter is always applied.
Sourcepub fn with_max_attempts(self, max_attempts: usize) -> Self
pub fn with_max_attempts(self, max_attempts: usize) -> Self
Maximum number of attempts per request. Setting it to 1 disables retrying. The default is to make 3 attempts.
Sourcepub fn with_compression(self, compression: bool) -> Self
pub fn with_compression(self, compression: bool) -> Self
Configure compression for requests and responses. Disabled by default.
Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !Freeze for ClientConfig
impl RefUnwindSafe for ClientConfig
impl Send for ClientConfig
impl Sync for ClientConfig
impl Unpin for ClientConfig
impl UnwindSafe for ClientConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request