iggy-rs / iggy

Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second.
https://iggy.rs
MIT License
2.09k stars 92 forks source link

Improve `IggyClient` interface #528

Open hubcio opened 10 months ago

hubcio commented 10 months ago

Currently, if someone wants to use IggyClient with custom server TCP address, following code is absolute minimum:

let tcp_client_config = TcpClientConfig {
    server_address: get_tcp_server_addr(),
    ..TcpClientConfig::default()
};
let tcp_client = Box::new(TcpClient::create(Arc::new(tcp_client_config)).unwrap());
let client = IggyClient::create(tcp_client, IggyClientConfig::default(), None, None, None);
client.connect().await?;
(...)

The aim of this task is to improve IggyClientBuilder and hide TcpClient, QuicClient and HttpClient.

IggyClientConfig should be renamed to something like IggyClientBackgroundConfig

After this task is done, IggyClientBuilder should look something like:

let config = TcpClientConfig {
            server_address: "127.0.0.1:8090".to_string(),
            reconnection_retries: 3,
            reconnection_interval: 1000,
            tls_enabled: false,
            tls_domain: "localhost".to_string(),
        } 
let client = IggyClientBuilder::new().with_config(config).build()?;
or
let client = IggyClientBuilder::new().with_tcp_config(config).build()?; // or http / quic if trait isn't possible
pradovic commented 9 months ago

As discussed, I'll try to tackle this one. I'll ping you guys on Discord if/when I have some questions/proposal.