blob: 086957968a0b0930107ad7f5a3c72b61cb0b5481 [file]
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use iggy::prelude::*;
use iggy_examples::shared::stream::PrintEventConsumer;
use tokio::sync::oneshot;
const IGGY_URL: &str = "iggy://iggy:iggy@localhost:8090";
#[tokio::main]
async fn main() -> Result<(), IggyError> {
println!("Build iggy client & consumer");
//For customization, use the `new` or `from_stream_topic` constructor
let config = IggyConsumerConfig::default();
let (client, mut consumer) =
IggyStreamConsumer::with_client_from_url(IGGY_URL, &config).await?;
println!("Start message stream");
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
match consumer
// PrintEventConsumer is imported from examples/src/shared/stream.rs
.consume_messages(&PrintEventConsumer {}, rx)
.await
{
Ok(_) => {}
Err(err) => eprintln!("Failed to consume messages: {err}"),
}
});
// Wait a bit for all messages to arrive.
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
println!("Stop the message stream and shutdown iggy client");
tx.send(()).expect("Failed to send shutdown signal");
client.shutdown().await?;
Ok(())
}