cploutarchou / tiny_kafka

This repository contains Rust-based implementations of a Kafka producer and a Kafka consumer. It leverages the `rdkafka` library to communicate with Kafka and manage the production and consumption of messages.
MIT License
1 stars 0 forks source link

error: failed to run custom build command for `rdkafka-sys v4.6.0+2.2.0` #1

Open taksedo opened 9 months ago

taksedo commented 9 months ago

Hello

After cargo build error appears:

error: failed to run custom build command for `rdkafka-sys v4.6.0+2.2.0`

Caused by:
  process didn't exit successfully: `D:\GitHub\learning\tiny_kafka\target\debug\build\rdkafka-sys-165221558fc0dc64\build-script-build` (exit code: 101)
  --- stdout
  Cloning librdkafka

  --- stderr
  Building and linking librdkafka statically
  Running command: "cp -a librdkafka/. D:\GitHub\learning\tiny_kafka\target\debug\build\rdkafka-sys-c133e4552a938a51\out" in dir: .
  thread 'main' panicked at C:\Users\xyb6qs\.cargo\registry\src\index.crates.io-6f17d22bba15001f\rdkafka-sys-4.6.0+2.2.0\build.rs:38:19:
  Command failed with error: program not found
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

rustc --version

rustc 1.74.0 (79e9716c9 2023-11-13)

rustup --version

rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.74.0 (79e9716c9 2023-11-13)`
cploutarchou commented 9 months ago

@taksedo can you try running using the following code?

use std::sync::Arc;
use tiny_kafka::consumer::KafkaConsumer;
use tiny_kafka::producer::{KafkaProducer, Message};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let rt = tokio::runtime::Runtime::new().unwrap();
    // Assuming kafka_bootstrap_servers is of type String
    let brokers = Arc::new("localhost:9092".to_string());
    let topics = Arc::new(vec!["test".to_string()]);

    // Consumer task
    let brokers_for_task1 = brokers.clone();
    let topics_for_task1 = topics.clone();
    let task1 = async move {
        let consumer = KafkaConsumer::new(
            brokers_for_task1.as_str(),
            "kafka-to-elastic",
            topics_for_task1.get(0).unwrap(),
        );
        loop {
if let Some(msg) = consumer.poll().await {
                info!(
                    "Consumed message with key: {} and value: {}",
                    msg.key, msg.value
                );
            }
        }
    };
    rt.spawn(task1);

    // Producer task
    let brokers_for_task2 = brokers.clone();
    let topics_for_task2 = topics.clone();
    let task2 = async move {
        let producer = KafkaProducer::new(brokers_for_task2.as_str(), Option::None);

        for i in 0..100 {
let key = format!("test_key_{}", i);
let value = format!("test_value_{}", i);
            let message = Message::new(&key, &value);

            producer
                .send_message(topics_for_task2.get(0).unwrap(), message)
                .await;
            tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
        }
    };
    rt.spawn(task2);

    // Wait for a ctrl-c signal
    tokio::signal::ctrl_c().await?;
    println!("ctrl-c received!");

    Ok(())
}

On my site, I dont get any errors!

ghajba commented 3 months ago

I want to share my 2 cents as I encountered the same issue today.

I am developing on Windows -- and got the same error: error: failed to run custom build command for rdkafka-sys v4.7.0+2.3.0 while using not tiny-kafka but simply rdkafka. There is some issue on this OS with building:

 failed to execute command: program not found
  is `cmake` not installed?

switching to the WSL solved my issue (after installing cmake). Maybe this will help future visitors.

cploutarchou commented 2 months ago

I want to share my 2 cents as I encountered the same issue today.

I am developing on Windows -- and got the same error: error: failed to run custom build command for rdkafka-sys v4.7.0+2.3.0 while using not tiny-kafka but simply rdkafka. There is some issue on this OS with building:

 failed to execute command: program not found
  is `cmake` not installed?

switching to the WSL solved my issue (after installing cmake). Maybe this will help future visitors.

Hi @ghajba

Thank you for bringing this to my attention.

I wanted to let you know that I am currently working on updating the GitHub repository to match the latest version on crates.io.

You can expect the updated version to be pushed to GitHub within the next few days. There will be no need to use any other Kafka dependencies.

Thank you for your patience and contribution.