infinyon / fluvio

Lean and mean distributed stream processing system written in rust and web assembly.
https://www.fluvio.io/
Apache License 2.0
2.77k stars 198 forks source link

[Bug]: Error while connecting to local cluster #4055

Closed jayeshpk1 closed 2 weeks ago

jayeshpk1 commented 4 weeks ago

What happened Getting this error called Result::unwrap() on an Err value: Config error: Config has no active profile

Expected behavior Should work

Describe the setup

How to reproduce it (as minimally and precisely as possible) Steps to reproduce the behavior:

  1. run the below code

Environment (please complete the following information):

Code

use async_std::stream::StreamExt;
use chrono::Local;
use fluvio::metadata::topic::TopicSpec;
use fluvio::{consumer::ConsumerConfigExtBuilder, Fluvio, RecordKey};

const TOPIC_NAME: &str = "hello-rust";
const PARTITION_NUM: u32 = 0;
const PARTITIONS: u32 = 1;
const REPLICAS: u32 = 1;

/// This is an example of a basic Fluvio workflow in Rust
///
/// 1. Establish a connection to the Fluvio cluster
/// 2. Create a topic to store data in
/// 3. Create a producer and send some bytes
/// 4. Create a consumer, and stream the data back
#[async_std::main]
async fn main() {
   // Connect to Fluvio cluster
   let fluvio = Fluvio::connect().await.unwrap();

   // Create a topic
   let admin = fluvio.admin().await;
   let topic_spec = TopicSpec::new_computed(PARTITIONS, REPLICAS, None);
   let _topic_create = admin
       .create(TOPIC_NAME.to_string(), false, topic_spec)
       .await;

   // Create a record
   let record = format!("Hello World! - Time is {}", Local::now().to_rfc2822());

   // Produce to a topic
   let producer = fluvio::producer(TOPIC_NAME).await.unwrap();
   producer.send(RecordKey::NULL, record).await.unwrap();
   // Fluvio batches outgoing records by default, so flush producer to ensure all records are sent
   producer.flush().await.unwrap();

   // Consume last record from topic
   let fluvio = Fluvio::connect().await.unwrap();
   let config = ConsumerConfigExtBuilder::default()
       .topic(TOPIC_NAME)
       .partition(PARTITION_NUM)
       .offset_start(fluvio::Offset::from_end(1))
       .build()
       .unwrap();

   let mut stream = fluvio.consumer_with_config(config).await.unwrap();
   if let Some(Ok(record)) = stream.next().await {
       let string = String::from_utf8_lossy(record.value());
       println!("{}", string);
   }
}
morenol commented 4 weeks ago

Hey, could you provide more information about:

1) how did you started the fluvio cluster? 2) how did you run the above code? Maybe using docker? 3) can you access the fluvio cluster from the CLI? 'fluvio topic list' works?

jayeshpk1 commented 4 weeks ago
  1. fluvio cluster start
  2. using "cargo run". I created a sample rust application using the example shown in documentation
  3. yes. below is the output. NAME TYPE PARTITIONS REPLICAS RETENTION TIME COMPRESSION DEDUPLICATION STATUS REASON quickstart-topic computed 1 1 7days any none resolution::provisioned my-topic computed 1 1 7days any none resolution::provisioned
ajhunyady commented 4 weeks ago

The client is looking for a profile file to get information about the cluster. You should have the following file on the system where the client is running:

ls ~/.fluvio/config 

can you confirm that the file is available?

With the profile in the right place, the code works:

 % cargo run            
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/test-client`
Hello World! - Time is Tue, 4 Jun 2024 17:20:30 -0700

After moving the profile:

 mv ~/.fluvio ~/.fluvio2

I get the following error:

% cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s
     Running `target/debug/test-client`
thread 'main' panicked at src/main.rs:20:41:
called `Result::unwrap()` on an `Err` value: Config error: Config has no active profile

Caused by:
    Config has no active profile
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
jayeshpk1 commented 4 weeks ago

Thank you so much. I was running cargo run from windows command line where configuration directory is missing.

ajhunyady commented 4 weeks ago

You can copy/paste it manually.

ajhunyady commented 3 weeks ago

@jayeshpk1, feel free to close if you think this issue has been resolved.