pub async fn start_client(
client_config: ClientConfiguration,
notification_rx: Receiver<ClientReadyMessage>,
shutdown: Option<Receiver<bool>>,
wait_for_shutdown_secs: Option<u64>,
) -> Result<(), Error>
Expand description
Start the client with provided ClientConfiguration
and Receiver<ClientReadyMessage>
channel.
Client listens for shutdown signals SIGTERM & SIGINT on Unix or CTRL-BREAK and CTRL-C on Windows.
Also accepts a Option<tokio::sync::watch::Receiver<bool>>
to shut down the client in addition to
system signals.
Examples found in repository?
examples/simple_client.rs (line 49)
24async fn main() -> Result<(), Error> {
25 tracing_subscriber::fmt().with_max_level(LevelFilter::DEBUG).init();
26
27 let config = ClientConfiguration::try_from(CLIENT_TOML_CONFIG)?;
28 let messages = get_test_messages(SAMPLE_MESSAGE_COUNT, NOTIFICATION_NAME);
29 let (interface_tx, interface_rx) = mpsc::channel(100);
30 let (shutdown_tx, shutdown_rx) = watch::channel(false);
31
32 tokio::spawn(async move {
33 info!("Sending test messages");
34 for message in messages {
35 match interface_tx.send(message).await {
36 Ok(_) => debug!("Sent test message to client"),
37 Err(error) => warn!("Unable to send test message to client: {}", error),
38 }
39 }
40 tokio::time::sleep(Duration::from_secs(1)).await;
41
42 // Send shutdown signal
43 if let Err(error) = shutdown_tx.send(true) {
44 error!("Unable to send shutdown signal: {}", error)
45 }
46 tokio::time::sleep(Duration::from_secs(1)).await;
47 });
48
49 start_client(config, interface_rx, Some(shutdown_rx), None).await?;
50
51 Ok(())
52}